|
| 18 Oct 2013 11:25 PM |
| I cannot seem to get any of my save/load scripts to work anyone have a simple one for KOs Captures and Cash? and can you add --explanation so i know how to script one correctly in the future? |
|
|
| Report Abuse |
|
|
|
| 18 Oct 2013 11:26 PM |
I think CM32 made something like that. It's something along the lines of DP.
"U BROKE THE TV U IDIOT!" - CeaselessSoul |
|
|
| Report Abuse |
|
|
Ekkoh
|
  |
| Joined: 22 Oct 2012 |
| Total Posts: 524 |
|
|
| 18 Oct 2013 11:27 PM |
I'll write you up one :)
"To sing when you live and to sing when you die" - George Ragan |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
Ekkoh
|
  |
| Joined: 22 Oct 2012 |
| Total Posts: 524 |
|
|
| 18 Oct 2013 11:42 PM |
Lemme know if it works
local Players = Game:GetService("Players") -- Make a variable referencing Game.Players local function PlayerAdded(plr) -- Setup a function to call on each player when they join local lstats = plr:WaitForChild("leaderstats") -- wait for leaderstats that will be inserted from a different script I'm assuming plr:WaitForDataReady() -- Call WaitForDataReady, necessary for loading and saving for n, stat in pairs(lstats:GetChildren()) do -- start looping through all of the stats inside 'leaderstats' local valueClass = stat.ClassName:sub(1, str:len()-5):lower() -- creates a variable referencing what type of value it is (i.e. Int, String, Boolean) if valueClass == "int" or valueClass == "number" then -- check the valueClass of each stat, LOAD it accordingly stat.Value = plr:LoadNumber(stat.Name) elseif valueClass == "string" then stat.Value = plr:LoadString(stat.Name) elseif valueClass == "bool" then stat.Value = plr:LoadBoolean(stat.Name) end end end local function PlayerLeaving(plr) if not plr.DataReady then -- if somehow data isn't ready by the time they leave the game, plr:WaitForDataReady() -- wait until it is end local lstats = plr:FindFirstChild("leaderstats") -- once again create a local variable for leaderstats for n, stat in pairs(lstats:GetChildren()) do -- start looping through leaderstats again local valueClass = stat.ClassName:sub(1, str:len()-5):lower() -- creates a variable referencing what type of value it is (i.e. Int, String, Boolean) if valueClass == "int" or valueClass == "number" then -- check the valueClass of each stat, SAVE it accordingly stat.Value = plr:SaveNumber(stat.Name, stat.Value) elseif valueClass == "string" then stat.Value = plr:SaveString(stat.Name, stat.Value) elseif valueClass == "bool" then stat.Value = plr:SaveBoolean(stat.Name, stat.Value) end end end Players.PlayerAdded:connect(PlayerAdded) -- Connect PlayerAdded function to PlayerAdded event (Member of Game.Players) Players.PlayerRemoving:connect(PlayerLeaving) -- Connect PlayerLeaving function to PlayerRemoving event (Member of Game.Players)
"To sing when you live and to sing when you die" - George Ragan |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 18 Oct 2013 11:45 PM |
there is no int in Lua All numbers are floats |
|
|
| Report Abuse |
|
|
Ekkoh
|
  |
| Joined: 22 Oct 2012 |
| Total Posts: 524 |
|
|
| 18 Oct 2013 11:58 PM |
There's a userdata object called IntValue... Are you misunderstanding my script?
"To sing when you live and to sing when you die" - George Ragan |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 19 Oct 2013 12:01 AM |
It doesn't matter, Lua interprets it as "number."
So: if valueClass == "int" is unneeded |
|
|
| Report Abuse |
|
|
Ekkoh
|
  |
| Joined: 22 Oct 2012 |
| Total Posts: 524 |
|
|
| 19 Oct 2013 12:06 AM |
Try this in the command line
val = Instance.new("IntValue", Workspace); print(val.ClassName:sub(1, val.ClassName:len()-5):lower())
"To sing when you live and to sing when you die" - George Ragan |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 19 Oct 2013 12:07 AM |
That just takes the first 3 letters of the classname...
You don't know what an integer is, do you... |
|
|
| Report Abuse |
|
|
Ekkoh
|
  |
| Joined: 22 Oct 2012 |
| Total Posts: 524 |
|
|
| 19 Oct 2013 12:10 AM |
Yes... which was my point. Not necessarily the first 3, it takes the substring all the way until "Value" so if it's "IntValue" it grabs "Int". I want it call SaveNumber on the leaderstat if the class is "IntValue" or "NumberValue". Yes, I do know what an integer is. -∞ to ∞ no decimals.
"To sing when you live and to sing when you die" - George Ragan |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
Ekkoh
|
  |
| Joined: 22 Oct 2012 |
| Total Posts: 524 |
|
|
| 19 Oct 2013 12:13 AM |
In that case it is, but if it was a StringValue I would want to take "String", not "Str". *Anyways*, that doesn't affect the script.
"To sing when you live and to sing when you die" - George Ragan |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 19 Oct 2013 12:15 AM |
I know how it works -.- It's the first 3, period.
lol123
lol = lol |
|
|
| Report Abuse |
|
|
Ekkoh
|
  |
| Joined: 22 Oct 2012 |
| Total Posts: 524 |
|
|
| 19 Oct 2013 12:17 AM |
Ummm no? Test it with StringValue!
val = Instance.new("StringValue", Workspace); print(val.ClassName:sub(1, val.ClassName:len()-5):lower())
"To sing when you live and to sing when you die" - George Ragan |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 19 Oct 2013 12:18 AM |
I'm not talking about the case of stringvalue I'm talking about the case of intvalue
Stop changing the subject |
|
|
| Report Abuse |
|
|
Ekkoh
|
  |
| Joined: 22 Oct 2012 |
| Total Posts: 524 |
|
|
| 19 Oct 2013 12:21 AM |
I'm not changing the subject, I'm explaining to you why you're incorrect. Doesn't matter, case closed, don't care enough to keep posting about something so trivial.
"To sing when you live and to sing when you die" - George Ragan |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 19 Oct 2013 12:22 AM |
I was correct
intvalue
:sub 3 is the same as -5 in that case
|
|
|
| Report Abuse |
|
|
Ekkoh
|
  |
| Joined: 22 Oct 2012 |
| Total Posts: 524 |
|
|
| 19 Oct 2013 12:29 AM |
You originally claimed
> "there is no int in Lua All numbers are floats"
Which was completely unrelated in the first place And I even said "In that case it is" So what are you trying to prove here
"To sing when you live and to sing when you die" - George Ragan |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 19 Oct 2013 12:37 AM |
All numbers in Lua are floats. idk |
|
|
| Report Abuse |
|
|
|
| 19 Oct 2013 12:40 AM |
| str: in line 7 is nil value |
|
|
| Report Abuse |
|
|
|
| 19 Oct 2013 12:42 AM |
Seriously, why save each individual value when you can just save the whole leaderstats instance?
game.Players.PlayerAdded:connect(function(Player) Player:WaitForDataReady()
-- create stat stuff here
local LoadedStats = Player:LoadInstance("Stats") if LoadedStats then Player:FindFirstChild("leaderstats"):Destroy() LoadedStats.Parent = Player end end)
game.Players.PlayerLeaving:connect(function(Player) Player:SaveInstance(Player:FindFirstChild("leaderstats"),"Stats") end)
--
Lua treats numbers as floating-point values, so saying that a number is an int is actually incorrect to some degree.
Typed languages would prevent you from doing this:
print(5 + 0.1)
But the Lua compiler automatically casts the numbers (ints, longs, doubles, floats, etc.) so that calculations work properly.
In typed languages, such as Java and C languages, to add a decimal (floating type) with an integer (whole number), you would need to cast the int to a float/double as such (well, like this in java, not sure about C languages)
int a = 5; double b = 0.5; double c = ((double) a) + b;
`(double) a` turning an int value to a double (floating type).
So because the Lua compiler/interpreter does this for us automatically, it's safe to say that we can call ints, longs, floats, doubles, and all the rest of them numbers. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 19 Oct 2013 12:42 AM |
| Remove the part "str:len()" |
|
|
| Report Abuse |
|
|
Ekkoh
|
  |
| Joined: 22 Oct 2012 |
| Total Posts: 524 |
|
|
| 19 Oct 2013 11:05 AM |
@Iam Or better yet, save a table of their data in a JSON object and save that string, and decode it to a table when you load the string.
"To sing when you live and to sing when you die" - George Ragan |
|
|
| Report Abuse |
|
|
|
| 19 Oct 2013 12:21 PM |
| Ok im confused now. The leaderboard is IntValue and has KOs Cash and Captures in it. |
|
|
| Report Abuse |
|
|