| |
|
|
| 25 Sep 2011 03:10 AM |
| I was new to data persistance once, then I made an api so I could test stuff in offline mode, it can be found here: http://www.roblox.com/DataPersistanceTestAPI-item?id=61468831 |
|
|
| Report Abuse |
|
|
| |
|
|
| 25 Sep 2011 03:32 AM |
local Use_DB = true
function saveStat(plr,val,key) if plr then plr:WaitForDataReady() plr:SaveNumber(key,val) end end
function loadStat(plr,key,stat) if plr then plr:WaitForDataReady() stat.Value = plr:LoadNumber(key,val) end end
game.Players.PlayerAdded:connect(function(player) Stat = Instance.new("IntValue",player) Stat.Name = "leaderstats" Altitude = Instance.new("IntValue",Stat) Altitude.Name = "Altitude" MaxAltitude = Instance.new("IntValue",Stat) MaxAltitude.Name = "MaxAltitude" while true do local f = player.Character Altitude.Value = f.Torso.Position.y-50 end end --this should be causing an error, replace with ) if Use_DP then loadStat(player,"MaxAltitude",MaxAltitude) end if Use_DP then --this will only be called when the player is added, try using MaxAltitued.Changed if f.Torso.Position.y-50 ~= Altitude.Value then if MaxAltitude.Value ~= Altitude.Value then saveStat(player,Altitude.Value,"MaxAltitude") end end end
|
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 25 Sep 2011 03:46 AM |
MaxAltitude.Changed:connect(function() saveStat(player,MaxAltitude.Value,"MaxAltitude") end)
or you could use the way I dislike, but should work
Max.Altitude.Changed:connect(function(value) saveStat(player,value,"MaxAltitude") end) |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 25 Sep 2011 04:04 AM |
local Use_DB = true
function saveStat(plr,val,key) if plr then plr:WaitForDataReady() plr:SaveNumber(key,val) end end
function loadStat(plr,key,stat) if plr then plr:WaitForDataReady() stat.Value = plr:LoadNumber(key,val) end end
game.Players.PlayerAdded:connect(function(player) Stat = Instance.new("IntValue",player) Stat.Name = "leaderstats" Altitude = Instance.new("IntValue",Stat) Altitude.Name = "Altitude" MaxAltitude = Instance.new("IntValue",Stat) MaxAltitude.Name = "MaxAltitude" while true do local f = player.Character Altitude.Value = f.Torso.Position.y-50 end end --nvm I missed the while my mistake if Use_DP then loadStat(player,"MaxAltitude",MaxAltitude) end if Use_DP then --this setion was changed MaxAltitude.Changed:connect(function() saveStat(player,MaxAltitude.Value,"MaxAltitude") end) end ) --this should probably be here to close the the PlayerAdded:connect( |
|
|
| Report Abuse |
|
|
| |
|
|
| 25 Sep 2011 04:14 AM |
local Use_DB = true function saveStat(plr,val,key) if plr then plr:WaitForDataReady() plr:SaveNumber(key,val) end end
function loadStat(plr,key,stat) if plr then plr:WaitForDataReady() stat.Value = plr:LoadNumber(key,val) end end
game.Players.PlayerAdded:connect( function(player) Stat = Instance.new("IntValue",player) Stat.Name = "leaderstats" Altitude = Instance.new("IntValue",Stat) Altitude.Name = "Altitude" MaxAltitude = Instance.new("IntValue",Stat) MaxAltitude.Name = "MaxAltitude" if Use_DP then --moved this above the while true do loadStat(player,"MaxAltitude",MaxAltitude) end MaxAltitude.Changed:connect( function() if player.Torso.Position.y-50 ~= Altitude.Value then if MaxAltitude.Value ~= Altitude.Value then saveStat(player,Altitude.Value,"MaxAltitude") end end end ) while true do --should be in the player added thingy local f = player.Character --not the best idea, but it works Altitude.Value = f.Torso.Position.y-50 wait() --prevents crashes end end )
|
|
|
| Report Abuse |
|
|
| |
|
|
| 25 Sep 2011 04:34 AM |
try this
local Use_DB = true function saveStat(plr,val,key) if plr then plr:WaitForDataReady() plr:SaveNumber(key,val) end end
function loadStat(plr,key,stat) if plr then plr:WaitForDataReady() stat.Value = plr:LoadNumber(key,val) end end
game.Players.PlayerAdded:connect( function(player) local Stat = Instance.new("IntValue",player) Stat.Name = "leaderstats" local Altitude = Instance.new("IntValue",Stat) Altitude.Name = "Altitude" local MaxAltitude = Instance.new("IntValue",Stat) MaxAltitude.Name = "MaxAltitude" while true do local f = player.Character Altitude.Value = f.Torso.Position.y-50 wait() if Use_DP then loadStat(player,"MaxAltitude",MaxAltitude) end end --needed an end here MaxAltitude.Changed:connect( function() if player.Torso.Position.y-50 ~= Altitude.Value then if MaxAltitude.Value ~= Altitude.Value then saveStat(player,Altitude.Value,"MaxAltitude") end end end ) end ) --the end was here
|
|
|
| Report Abuse |
|
|
myrco919
|
  |
| Joined: 12 Jun 2009 |
| Total Posts: 13241 |
|
| |
|
| |
|
|
| 25 Sep 2011 04:49 AM |
Workspae.Script:26:Attempt to something about f being undefined |
|
|
| Report Abuse |
|
|
| |
|
|
| 25 Sep 2011 04:57 AM |
| if it doesn't work i could check the problem with my api |
|
|
| Report Abuse |
|
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
| 25 Sep 2011 05:22 AM |
try testing this in studio with local Use_DP=false |
|
|
| Report Abuse |
|
|