generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

R

Previous Thread :: Next Thread 
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
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
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
15 Jul 2012 06:53 PM
noone?
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
15 Jul 2012 07:00 PM
HELLO?!?!?!?!??!
Report Abuse
Techwiz19 is not online. 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
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
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 is not online. 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
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
15 Jul 2012 07:15 PM
Do I replace that with what?
Report Abuse
Techwiz19 is not online. 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
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
15 Jul 2012 07:20 PM
Still doesn't work
Report Abuse
Techwiz19 is not online. 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
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
15 Jul 2012 07:27 PM
Still doesn't work
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image