DeVinci
|
  |
| Joined: 21 Jul 2010 |
| Total Posts: 338 |
|
|
| 28 Apr 2012 11:01 AM |
Ok, so now I've converted my leaderboard into a Data Persistance leaderboard in hopes of saving stats. But the leaderboard doesn't show up and I'm guessing it doesn't save either. What did I do wrong?
function saveScore(player, score) player:SaveNumber("Points", score) player:SaveNumber("MaxHealth", mhealth) player:SaveNumber("Health", health) player:SaveNumber("WalkSpeed", speed) end
function loadScore(player, clickCounter)
local score = player:LoadNumber("Points") local mhealth = player:LoadNumber("MaxHealth") local health = player:LoadNumber("Health") local speed = player:LoadNumber("WalkSpeed") if score ~= 0 then clickCounter.Value = score else print("Nothing to load/score was 0") end
end
function onPlayerEntered(newPlayer)
local stats = Instance.new("IntValue") stats.Name = "leaderstats"
local points = Instance.new("IntValue") points.Name = "Points" points.Value = 500
local mhealth = Instance.new("IntValue")--Max Health mhealth.Name = "MaxHealth" mhealth.Value = newPlayer.Character.Humanoid.MaxHealth
local health = Instance.new("IntValue")--Health health.Name = "Health" health.Value = newPlayer.Character.Humanoid.Health
local speed = Instance.new("IntValue")--WalkSpeed speed.Name = "WalkSpeed" speed.Value = newPlayer.Character.Humanoid.WalkSpeed
points.Parent = stats mhealth.Parent = newPlayer health.Parent = newPlayer speed.Parent = newPlayer stats.Parent = newPlayer
newPlayer:WaitForDataReady()
loadScore(newPlayer, points) loadScore(newPlayer, mhealth) loadScore(newPlayer, health) loadScore(newPlayer, speed)
end
function onPlayerRemoving(player) print("Attempting to save score for " .. player.Name) local stats = player:FindFirstChild("leaderstats") if (stats ~= nil) then local clicks = stats:FindFirstChild("Points") if (clicks ~= nil) then saveScore(player, clicks.Value) saveScore(player, mhealth.Value) saveScore(player, health.Value) saveScore(player, speed.Value) end end end
game.Players.PlayerAdded:connect(onPlayerEntered) game.Players.PlayerRemoving:connect(onPlayerRemoving) |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2012 11:06 AM |
Made SO much simpler, and possibly fixed:
game.oPs.oPAdded:connect(function(nP) nP:WaitForDataReady() local stats = Instance.new("IntValue") stats.Name = "leaderstats" local points = Instance.new("IntValue") points.Name = "Points" points.Value = 500 local mhealth = Instance.new("IntValue")--Max Health mhealth.Name = "MaxHealth" mhealth.Value = nP.Character.Humanoid.MaxHealth local health = Instance.new("IntValue")--Health health.Name = "Health" health.Value = nP.Character.Humanoid.Health local speed = Instance.new("IntValue")--WalkSpeed speed.Name = "WalkSpeed" speed.Value = nP.Character.Humanoid.WalkSpeed points.Parent = stats mhealth.Parent = nP health.Parent = nP speed.Parent = nP stats.Parent = nP points.Value = nP:LoadNumber("Points") mhealth.Value = nP:LoadNumber("MaxHealth") health.Value = nP:LoadNumber("Health") speed.Value = nP:LoadNumber("WalkSpeed") end) game.oPs.oPRemoving:connect(function(oP) oP:SaveNumber("Points", oP.leaderstats.Points.Value) oP:SaveNumber("MaxHealth", oP.leaderstats.MaxHealth.Value) oP:SaveNumber("Health", oP.leaderstats.Health.Value) oP:SaveNumber("WalkSpeed", oP.leaderstats.WalkSpeed.Value) end) |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2012 11:07 AM |
Oops, darn, I forgot about my auto-replace thing, try this:
game.Players.PlayerAdded:connect(function(nP) nP:WaitForDataReady() local stats = Instance.new("IntValue") stats.Name = "leaderstats" local points = Instance.new("IntValue") points.Name = "Points" points.Value = 500 local mhealth = Instance.new("IntValue")--Max Health mhealth.Name = "MaxHealth" mhealth.Value = nP.Character.Humanoid.MaxHealth local health = Instance.new("IntValue")--Health health.Name = "Health" health.Value = nP.Character.Humanoid.Health local speed = Instance.new("IntValue")--WalkSpeed speed.Name = "WalkSpeed" speed.Value = nP.Character.Humanoid.WalkSpeed points.Parent = stats mhealth.Parent = nP health.Parent = nP speed.Parent = nP stats.Parent = nP points.Value = nP:LoadNumber("Points") mhealth.Value = nP:LoadNumber("MaxHealth") health.Value = nP:LoadNumber("Health") speed.Value = nP:LoadNumber("WalkSpeed") end) game.Players.PlayerRemoving:connect(function(oP) oP:SaveNumber("Points", oP.leaderstats.Points.Value) oP:SaveNumber("MaxHealth", oP.leaderstats.MaxHealth.Value) oP:SaveNumber("Health", oP.leaderstats.Health.Value) oP:SaveNumber("WalkSpeed", oP.leaderstats.WalkSpeed.Value) end)
|
|
|
| Report Abuse |
|
|
DeVinci
|
  |
| Joined: 21 Jul 2010 |
| Total Posts: 338 |
|
|
| 28 Apr 2012 11:12 AM |
| The script says points start out at 500... but... In-game you start out with 0... Da heck? |
|
|
| Report Abuse |
|
|
DeVinci
|
  |
| Joined: 21 Jul 2010 |
| Total Posts: 338 |
|
|
| 28 Apr 2012 11:13 AM |
| Wait... Maybe my fail of script DID save.... when it was at 0. How do I clear Data Persistance for a player? |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2012 11:13 AM |
Just save the values to nil.
~umad~ |
|
|
| Report Abuse |
|
|
DeVinci
|
  |
| Joined: 21 Jul 2010 |
| Total Posts: 338 |
|
| |
|
|
| 28 Apr 2012 11:14 AM |
Save the values to nil, and it will clear saved data.
~umad~ |
|
|
| Report Abuse |
|
|
DeVinci
|
  |
| Joined: 21 Jul 2010 |
| Total Posts: 338 |
|
|
| 28 Apr 2012 11:16 AM |
player:SaveNumber("Points", nil)
Like That?
|
|
|
| Report Abuse |
|
|
| |
|
DeVinci
|
  |
| Joined: 21 Jul 2010 |
| Total Posts: 338 |
|
| |
|
DeVinci
|
  |
| Joined: 21 Jul 2010 |
| Total Posts: 338 |
|
| |
|
|
| 28 Apr 2012 11:29 AM |
game.Players.PlayerAdded:connect(function(nP) nP:WaitForDataReady() local stats = Instance.new("IntValue") stats.Name = "leaderstats" local points = Instance.new("IntValue") points.Name = "Points" points.Value = 500 local mhealth = Instance.new("IntValue")--Max Health mhealth.Name = "MaxHealth" mhealth.Value = nP.Character.Humanoid.MaxHealth local health = Instance.new("IntValue")--Health health.Name = "Health" health.Value = nP.Character.Humanoid.Health local speed = Instance.new("IntValue")--WalkSpeed speed.Name = "WalkSpeed" speed.Value = nP.Character.Humanoid.WalkSpeed points.Parent = stats mhealth.Parent = nP health.Parent = nP speed.Parent = nP stats.Parent = nP if nP:LoadNumber("Points") ~= 0 then points.Value = nP:LoadNumber("Points") end mhealth.Value = nP:LoadNumber("MaxHealth") health.Value = nP:LoadNumber("Health") speed.Value = nP:LoadNumber("WalkSpeed") end) game.Players.PlayerRemoving:connect(function(oP) oP:SaveNumber("Points", oP.leaderstats.Points.Value) oP:SaveNumber("MaxHealth", oP.leaderstats.MaxHealth.Value) oP:SaveNumber("Health", oP.leaderstats.Health.Value) oP:SaveNumber("WalkSpeed", oP.leaderstats.WalkSpeed.Value) end)
|
|
|
| Report Abuse |
|
|
DeVinci
|
  |
| Joined: 21 Jul 2010 |
| Total Posts: 338 |
|
|
| 28 Apr 2012 11:34 AM |
3 Problems:
Wouldn't that help anyone who started with 500, spent all of it, left and came back and magically got another 500?
My maxhealth and walkspeed are normal! D:
And... I get loopkilled once I die for the first time... |
|
|
| Report Abuse |
|
|
DeVinci
|
  |
| Joined: 21 Jul 2010 |
| Total Posts: 338 |
|
| |
|
DeVinci
|
  |
| Joined: 21 Jul 2010 |
| Total Posts: 338 |
|
| |
|
DeVinci
|
  |
| Joined: 21 Jul 2010 |
| Total Posts: 338 |
|
|
| 28 Apr 2012 01:13 PM |
Ok, I think I MAY have a solution, but It needs to be put in the right spot.
game.Players.PlayerAdded:connect(function(nP) nP:WaitForDataReady() local stats = Instance.new("IntValue") stats.Name = "leaderstats" local points = Instance.new("IntValue") points.Name = "Points" points.Value = 500 local mhealth = Instance.new("IntValue")--Max Health mhealth.Name = "MaxHealth" mhealth.Value = nP.Character.Humanoid.MaxHealth local health = Instance.new("IntValue")--Health health.Name = "Health" health.Value = nP.Character.Humanoid.Health local speed = Instance.new("IntValue")--WalkSpeed speed.Name = "WalkSpeed" speed.Value = nP.Character.Humanoid.WalkSpeed points.Parent = stats mhealth.Parent = nP health.Parent = nP speed.Parent = nP stats.Parent = nP if nP:LoadNumber("Points") ~= 0 then points.Value = nP:LoadNumber("Points") end mhealth.Value = nP:LoadNumber("MaxHealth") health.Value = nP:LoadNumber("Health") speed.Value = nP:LoadNumber("WalkSpeed") end) game.Players.PlayerRemoving:connect(function(oP) oP:SaveNumber("Points", oP.leaderstats.Points.Value) oP:SaveNumber("MaxHealth", op.MaxHealth.Value) oP:SaveNumber("Health", oP.Health.Value) oP:SaveNumber("WalkSpeed", oP.WalkSpeed.Value) end)
Heres what I think is the solution, I tried putting it after the LoadNumber codes but that didnt work. Heres the code:
np.Character.Humanoid.MaxHealth = mhealth.Value np.Character.Humanoid.Health = health.Value np.Character.Humanoid.WalkSpeed= speed.Value
Where should I put this? If it IS the right code, anyway... |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2012 01:55 PM |
I'd put this after the line: "speed.Value = nP:LoadNumber("WalkSpeed")":
nP.Character.Humanoid.MaxHealth = mhealth.Value nP.Character.Humanoid.Health = health.Value nP.Character.Humanoid.WalkSpeed= speed.Value
-- you forgot to capitalize the P in nP.
~umad~ |
|
|
| Report Abuse |
|
|
DeVinci
|
  |
| Joined: 21 Jul 2010 |
| Total Posts: 338 |
|
|
| 28 Apr 2012 03:42 PM |
I fixed it already XD
put this in my on respawn script:
player:WaitForDataReady() Wait(1) the code.
lol
|
|
|
| Report Abuse |
|
|