Advertisement - Why am I seeing ads? Report
   
 

Data Persistence

Sort:
Previous Thread :: Next Thread 
jimmybolt77 is not online. jimmybolt77
Joined: 06 Jul 2008
Total Posts: 292
29 Feb 2012 03:05 PM
When I test it out I step on a brick that changes my level to 10, but when I leave and rejoin it doesn't save.

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

local stats = player:FindFirstChild("leaderstats")
if not stats then return end

local level = stats:FindFirstChild("Level")
if not level then return end
local exp = stats:FindFirstChild("EXP")
if not exp then return end

local gold = stats:FindFirstChild("Gold")
if not gold then return end

player:SaveNumber("EXP", exp.Value)
player:SaveNumber("Gold", gold.Value)
player:SaveNumber("Level", level.Value)
end)



game.Players.PlayerAdded:connect(function(p)
p:WaitForDataReady()
local ls = Instance.new("IntValue", p)
ls.Name = "leaderstats"
local lev = Instance.new("IntValue", ls)
lev.Name = "Level"
local exp = Instance.new("IntValue", ls)
exp.Name = "EXP"
local gold = Instance.new("IntValue", ls)
gold.Name = "Gold"
SavedLevel = p:LoadNumber("Level")
SavedExp = p:LoadNumber("EXP")
SavedGold = p:LoadNumber("Gold")
if SavedLevel == 0 then
SavedLevel = 1
end
if SavedGold == 0 then
SavedGold = 1
end
if SavedExp == 0 then
SavedExp = 1
end
lev.Value = SavedLevel
gold.Value = SavedGold
exp.Value = SavedExp

end)



function onChatted(msg, speaker)
source = string.lower(speaker.Name)
msg = string.lower(msg)
if msg == "save" then

local stats = speaker:FindFirstChild("leaderstats")
if not stats then return end

local level = stats:FindFirstChild("Level")
if not level then return end

local exp = stats:FindFirstChild("EXP")
if not exp then return end

local gold = stats:FindFirstChild("Gold")
if not gold then return end

player:SaveNumber("Level", level.Value)
player:SaveNumber("EXP", exp.Value)
player:SaveNumber("Gold", gold.Value)

end
end

function onPlayerEntered(newPlayer)
newPlayer.Chatted:connect(function(msg) onChatted(msg, newPlayer) end)
end

game.Players.ChildAdded:connect(onPlayerEntered)
ReplyReport Abuse
rangersmash is not online. rangersmash
Joined: 18 Nov 2009
Total Posts: 2839
29 Feb 2012 03:09 PM
[ Content Deleted ]
Report Abuse
jimmybolt77 is not online. jimmybolt77
Joined: 06 Jul 2008
Total Posts: 292
29 Feb 2012 03:20 PM
The auto save still won't work...
ReplyReport Abuse
Cakins is not online. Cakins
Joined: 23 Jul 2009
Total Posts: 307
29 Feb 2012 03:36 PM
Keep in mind if you are testing this, it will only work in Live mode.
ReplyReport Abuse
jimmybolt77 is not online. jimmybolt77
Joined: 06 Jul 2008
Total Posts: 292
29 Feb 2012 03:40 PM
I click play on my game, if that is what you mean by Live.
ReplyReport Abuse
nightmare3o is not online. nightmare3o
Joined: 21 Jun 2008
Total Posts: 927
29 Feb 2012 03:48 PM
You have the saving good but I don't see any loading.
ReplyReport Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
Add a Reply
 
   
 
Advertisement Report