|
| 15 Jul 2012 06:44 PM |
When you click the button, it clears your score (that is what it is intended to do) and I have a Data Persistance script that works, but doesn't save the score to 0 when this is clicked. It works fine, but data persistance doesn't save the cleared score when the player leaves so when the player comes back, they still have their old score.
This is the line that clears the score (Works):
script.Parent.Parent.Parent.Parent.leaderstats.Points.Value = 0
and here is the data persistance that doesn't save the players score to 0 (just a part of a DP script, this is the player removing part):
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) end end end game.Players.PlayerRemoving:connect(onPlayerRemoving) |
|
|
| Report Abuse |
|
|
| |
|
| |
|
Techwiz19
|
  |
| Joined: 30 Jan 2011 |
| Total Posts: 462 |
|
|
| 15 Jul 2012 07:05 PM |
| Read the dada persistence tutorial on the wiki. Actually read it. saveScore isnt how you use DP. |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2012 07:12 PM |
@tech, so I got the script from the wiki, edited the "Score" to "Points" but doesn't work
scoreKey = "PlayerScore"
game.Players.PlayerAdded:connect(function(player) player:WaitForDataReady()
-- create leaderboard local ls = Instance.new("IntValue") ls.Name = "leaderstats" ls.Parent = player
--create the score stat local score = Instance.new("IntValue") score.Name = "Points" score.Parent = ls
local succ,ret = pcall(function() player:LoadNumber(scoreKey) end) if succ then if ret ~= 0 then player.leaderstats.Points.Value = ret else print("Nothing to load/score was 0") end else print("Error:",ret) end
end)
game.Players.PlayerRemoving:connect(function(player) local succ,ret = pcall(function() player:SaveNumber(scoreKey,player.leaderstats.Points) end) --if a player leaves before the leaderstats have been created, as it's in a pcall it won't crash the script if succ then print("Successfully saved") else print("Saving error:",ret) end end) |
|
|
| Report Abuse |
|
|
Techwiz19
|
  |
| Joined: 30 Jan 2011 |
| Total Posts: 462 |
|
|
| 15 Jul 2012 07:15 PM |
The thing is, DP doesnt always work because there isnt always enough time to save when a player leaves.
Instead of the PlayerRemoving event try
player.leaderstats.Points.Changed:connect(function() local succ,ret = pcall(function() player:SaveNumber(scoreKey,player.leaderstats.Points) end) --if a player leaves before the leaderstats have been created, as it's in a pcall it won't crash the script if succ then print("Successfully saved") else print("Saving error:",ret) end end)
so it saves whenever the points change. |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2012 07:15 PM |
| Do I replace that with what? |
|
|
| Report Abuse |
|
|
Techwiz19
|
  |
| Joined: 30 Jan 2011 |
| Total Posts: 462 |
|
|
| 15 Jul 2012 07:16 PM |
| Replace the PlayerRemoving event with that. The part that saves. Read the script possibly to TRY and understand it? |
|
|
| Report Abuse |
|
|
| |
|
Techwiz19
|
  |
| Joined: 30 Jan 2011 |
| Total Posts: 462 |
|
|
| 15 Jul 2012 07:22 PM |
player.leaderstats.Points.Changed:connect(function() player:WaitForDataReady() local succ,ret = pcall(function() player:SaveNumber(scoreKey,player.leaderstats.Points) end) --if a player leaves before the leaderstats have been created, as it's in a pcall it won't crash the script if succ then print("Successfully saved") else print("Saving error:",ret) end end)
|
|
|
| Report Abuse |
|
|
| |
|