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
 

Re: Forecfully save?

Previous Thread :: Next Thread 
MattJon is not online. MattJon
Joined: 28 Apr 2009
Total Posts: 660
07 Apr 2013 07:57 PM
When using data Persistance, is it not enough to have the leaderboard script? Do you have to have something to forcefully save a value? If so, what is it? All I have is my leaderboard with data persistance.

--------------------------------------------------------------

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 = "Treasure"
score.Parent = ls

local ok, ret = pcall(function() return player:LoadNumber(scoreKey) end)
if ok then
if ret ~= 0 then
score.Value = ret
else
print("Nothing to load/score was 0")
end
else
print("Error:", ret)
end

end)

game.Players.PlayerRemoving:connect(function(player)
--if a player leaves before the leaderstats have been created it won't crash the script, as it's in a pcall
local succ, ret = pcall(function() player:SaveNumber(scoreKey,player.leaderstats.Score) end)
if succ then
print("Successfully saved")
else
print("Saving error:", ret)
end
end)
Report Abuse
DonnyTheDemented is not online. DonnyTheDemented
Joined: 29 May 2010
Total Posts: 1413
07 Apr 2013 08:01 PM
You might want to save at intervals, incase someone crashes and is instantly removed from the game.

But no there is no way to "force" save. Saving does not work in play solo due to the players ability to be different characters (Player1, Player2, etc).
Report Abuse
MattJon is not online. MattJon
Joined: 28 Apr 2009
Total Posts: 660
07 Apr 2013 08:03 PM
Well, yes but I'm asking how to save. Does it do that automatically?
Report Abuse
MattJon is not online. MattJon
Joined: 28 Apr 2009
Total Posts: 660
07 Apr 2013 08:14 PM
Bump.
Report Abuse
FoggedOut is not online. FoggedOut
Joined: 09 Dec 2011
Total Posts: 3021
07 Apr 2013 08:19 PM
Heres what I use to save my LeaderBoard Stats. Just showing you:

function onPlayerEntered(player)
wait()
player:WaitForDataReady()
repeat wait() until player:FindFirstChild("leaderstats")
if player.DataReady then
if player:findFirstChild("leaderstats") then
local score = player.leaderstats:GetChildren()
for i = 1,#score do
local ScoreLoaded = player:LoadNumber(score[i].Name)
wait()
if ScoreLoaded ~= 0 then
score[i].Value = ScoreLoaded
end
end
end
end
end

function onPlayerLeaving(player)
if player:findFirstChild("leaderstats") then
local score = player.leaderstats:GetChildren()
for i = 1,#score do
player:SaveNumber(score[i].Name,score[i].Value)
end
end
end

game.Players.PlayerAdded:connect(onPlayerEntered)
game.Players.PlayerRemoving:connect(onPlayerLeaving)


Yeah, its quite simple.
Report Abuse
MattJon is not online. MattJon
Joined: 28 Apr 2009
Total Posts: 660
07 Apr 2013 08:25 PM
Very nice. So this would be a script separate from the leaderboard? And if I wanted to save a StringValue? Would I merely change LoadNumber and SaveNumber to LoadString and SaveString? (and ya'know leaderstats to leaderstats2, or whatever personal touch I want to add)
Report Abuse
FoggedOut is not online. FoggedOut
Joined: 09 Dec 2011
Total Posts: 3021
07 Apr 2013 08:28 PM
Yes it would be seperate. If its not seperate, than its VERY hard to edit.
Report Abuse
MattJon is not online. MattJon
Joined: 28 Apr 2009
Total Posts: 660
07 Apr 2013 08:58 PM
That script works BEAUTIFULLY for IntValues. I am not advanced enough however to edit it for StringValues. I tried and failed. Any successful results I will reward. Please
Report Abuse
FoggedOut is not online. FoggedOut
Joined: 09 Dec 2011
Total Posts: 3021
07 Apr 2013 09:00 PM
Sorry, I eally cant make somthing like that gain but with different values. xD That script took me weeks to figure out, edit, and I tested it ingame around 50+ times. Besides, I'm working on my own crazy game, and I'm really sorry I cant help any more. :)
Report Abuse
MattJon is not online. MattJon
Joined: 28 Apr 2009
Total Posts: 660
07 Apr 2013 09:20 PM
Ba-dump
Report Abuse
MattJon is not online. MattJon
Joined: 28 Apr 2009
Total Posts: 660
07 Apr 2013 09:26 PM
Nevermind... Me, being the idiot I am, never switched SaveNumber and LoadNumber to SaveString and LoadString
Report Abuse
FoggedOut is not online. FoggedOut
Joined: 09 Dec 2011
Total Posts: 3021
07 Apr 2013 10:34 PM
Haha, never thought it would be that easy. xD
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