generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Saving a random variable

Previous Thread :: Next Thread 
DaveHereYouTube is not online. DaveHereYouTube
Joined: 13 May 2016
Total Posts: 213
15 Aug 2016 08:40 PM
Hey guys and gals! I wanting to save a variable for unlocking a mission in the game. I already have a script in the onplayeradd and playerleaving for strength and defense. However I don't want this variable to be shown as a leaderstat. All of the tutorials I've read show how to save a variable under leaderstat that shows on the leaderboard.

Is there a way to save a variable for each player that wouldn't be shown on the leaderboard? The easier the better :)

Example of what I use onPlayerAdded

local DataStore = game:GetService("DataStoreService"):GetDataStore("DaveStore")

game.Players.PlayerAdded:connect(function(player)

stats = Instance.new("IntValue", player)
stats.Name = "leaderstats"

Strength = Instance.new("IntValue",stats)
Strength.Name = "Strength"

Defense = Instance.new("IntValue", stats)
Defense.Name = "Defense"

local key = "player-"..player.userId

local savedValues = DataStore:GetAsync(key)

if savedValues then
--Save format: (Strength, Defense)
Strength.Value = savedValues[1]
Defense.Value = savedValues[2]
else
local valuesToSave = {Strength.Value, Defense.Value}
DataStore:SetAsync(key, valuesToSave)
end
end)

What I use on playerLeaving

local DataStore = game:GetService("DataStoreService"):GetDataStore("DaveStore")

game.Players.PlayerRemoving:connect(function(player)

local key = "player-"..player.userId

--Save key: (Strength, Defense)
local valuesToSave = {player.leaderstats.Strength.Value, player.leaderstats.Defense.Value}
DataStore:SetAsync(key, valuesToSave)
end)
Report Abuse
ColonySimulator is not online. ColonySimulator
Joined: 05 Jul 2015
Total Posts: 1721
15 Aug 2016 08:46 PM
Well dont set your stats as child of leaderstats? like you can make another parent and set them to this one. Leaderstats is the thing that make your leaderboard because of a roblox thing idk. so if you set your stats as the child of something else then it not going to show on leaderboard cause the leaderboard aint recognizing them as their true children.
Report Abuse
Dralian is not online. Dralian
Joined: 21 Mar 2013
Total Posts: 7624
15 Aug 2016 08:55 PM
r u making a dbz game or naw
Report Abuse
DaveHereYouTube is not online. DaveHereYouTube
Joined: 13 May 2016
Total Posts: 213
15 Aug 2016 09:37 PM
That worked great ColonySimulater! Thanks for the advice! :D
Report Abuse
DaveHereYouTube is not online. DaveHereYouTube
Joined: 13 May 2016
Total Posts: 213
15 Aug 2016 09:37 PM
Yeah, its a dragon ball game
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
15 Aug 2016 10:23 PM
https://forum.roblox.com/Forum/ShowPost.aspx?PostID=195621950


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image