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: My Data Presistence never works.

Previous Thread :: Next Thread 
MARIOSTAR6464 is not online. MARIOSTAR6464
Joined: 21 Jul 2008
Total Posts: 13674
11 Aug 2011 12:05 PM
I believe the save does, but when the player rejoins a game, it doesn't load.

I tested this online, I will mark out the irrelavent parts to have a look at:




function saveScore(player, score)
player:WaitForDataReady()
player:SaveNumber("Cash", score)
player:SaveNumber("Level", score)
player:SaveNumber("Fuel", score)
end


function loadScore(player, Counter)
player:WaitForDataReady()
local score = player:LoadNumber("Cash")
local score2 = player:LoadNumber("Level")
local score3 = player:LoadNumber("Fuel")

if score ~= 0 then
Counter.Value = score
Counter.Value = score2
Counter.Value = score3
else
print("Nothing to load/score was 0")
end

end




--IGNORE THIS PART

game.Players.PlayerAdded:connect(function(Player)
local Leaderstats = Instance.new("IntValue")
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = Player

local Points = Instance.new("IntValue", Player)
Points.Name = "TestPoints"
Points.Value = 0

local Fuel = Instance.new("IntValue", Player)
Fuel.Name = "Fuel"
Fuel.Value = 0

local Cash = Instance.new("IntValue", Leaderstats)
Cash.Name = "Cash"
Cash.Value = 0

local Level = Instance.new("IntValue", Leaderstats)
Level.Name = "Level"
Level.Value = 1
---------


Player:WaitForDataReady()
loadScore(Player, Cash)
loadScore(Player, Level)
loadScore(Player, Fuel)


--IGNORE THIS PART
local OneHundred = 100
local RealPoints = 0
local OldPoints = Player.TestPoints.Value
Player.TestPoints.Changed:connect(function(Val)
RealPoints = RealPoints + (Val - OldPoints)
OldPoints = Val
if RealPoints >= 100 then
RealPoints = RealPoints - 100
Level.Value = Level.Value + 1
end
end)
end)
---------

game.Players.PlayerRemoving:connect(function(OldPlayer)
print("Attempting to save score for " .. OldPlayer.Name)
local stats = OldPlayer:FindFirstChild("leaderstats")
if (stats ~= nil) then
local cash = stats:FindFirstChild("Cash")
if (cash ~= nil) then
saveScore(OldPlayer, cash.Value)
local level = stats:FindFirstChild("Level")
if (level ~= nil) then
saveScore(OldPlayer, level.Value)
local fuel = OldPlayer:FindFirstChild("Fuel")
if (fuel ~= nil) then
saveScore(OldPlayer, fuel.Value)
end
end
end
end
end)
Report Abuse
MARIOSTAR6464 is not online. MARIOSTAR6464
Joined: 21 Jul 2008
Total Posts: 13674
11 Aug 2011 12:09 PM
It's long, but not complicated.

If you can't help, then just to help me get this fixed, please bump it.
Report Abuse
MARIOSTAR6464 is not online. MARIOSTAR6464
Joined: 21 Jul 2008
Total Posts: 13674
11 Aug 2011 12:28 PM
♪ ♫ ♪~ No one ever helps me with Data Presistance, I'm starting to think no one know Data Presistance ~♪ ♫ ♪
Report Abuse
darkkiller5555 is not online. darkkiller5555
Joined: 22 Nov 2009
Total Posts: 6359
11 Aug 2011 12:31 PM
I'd totally help. Thing is I haven't had studio since before DP came out, so I'm screwed over with the new features. :D Wait, that's a bad thing. >.>
Report Abuse
bballer13sn is not online. bballer13sn
Joined: 03 Jun 2009
Total Posts: 2490
11 Aug 2011 12:32 PM
There is nothing that I can that is wrong. May I ask if it loads any scores, and what OUtput says?
Report Abuse
MARIOSTAR6464 is not online. MARIOSTAR6464
Joined: 21 Jul 2008
Total Posts: 13674
11 Aug 2011 12:32 PM
Lol, ok. Thanks for the bump.


I think i found the problem, it is within the save, it reaches the first print, but never the last one:

game.Players.PlayerRemoving:connect(function(OldPlayer)
print("Attempting to save score for " .. OldPlayer.Name)
local stats = OldPlayer:FindFirstChild("leaderstats")
if (stats ~= nil) then
local cash = stats:FindFirstChild("Cash")
if (cash ~= nil) then
saveScore(OldPlayer, cash.Value)
local level = stats:FindFirstChild("Level")
if (level ~= nil) then
saveScore(OldPlayer, level.Value)
local fuel = OldPlayer:FindFirstChild("Fuel")
if (fuel ~= nil) then
saveScore(OldPlayer, fuel.Value)
print("Score saved for " .. OldPlayer.Name)
end
end
end
end
end)
Report Abuse
MARIOSTAR6464 is not online. MARIOSTAR6464
Joined: 21 Jul 2008
Total Posts: 13674
11 Aug 2011 12:33 PM
Output:

Player 0 added
Thu Aug 11 18:30:47 2011 - Lost connection to 127.0.0.1:1129
Player 0 leaving
Attempting to save score for Player
Report Abuse
bballer13sn is not online. bballer13sn
Joined: 03 Jun 2009
Total Posts: 2490
11 Aug 2011 12:37 PM
game.Players.PlayerRemoving:connect(function(OldPlayer)
print("Attempting to save score for " .. OldPlayer.Name)
local stats = OldPlayer:FindFirstChild("leaderstats")
if stats then
local cash = stats:FindFirstChild("Cash")
if cash then
OldPlayer:saveScore("Cash", cash.Value)
local level = stats:FindFirstChild("Level")
if level then
OldPlayer:saveScore("Level", level.Value)
local fuel = OldPlayer:FindFirstChild("Fuel")
if fuel then
OldPlayer:saveScore("Fuel", fuel.Value)
print("Score saved for " .. OldPlayer.Name)
end
end
end
end
end)
Report Abuse
bballer13sn is not online. bballer13sn
Joined: 03 Jun 2009
Total Posts: 2490
11 Aug 2011 12:42 PM
Or you can try a more efficient version:

game.Players.PlayerRemoving:connect(function(OldPlayer)
print("Attempting to save score for " .. OldPlayer.Name)
local stats = OldPlayer:FindFirstChild("leaderstats")
if stats then
local cash = stats:FindFirstChild("Cash")
if cash then
OldPlayer:saveScore("Cash", cash.Value)
end
local level = stats:FindFirstChild("Level")
if level then
OldPlayer:saveScore("Level", level.Value)
end
local fuel = OldPlayer:FindFirstChild("Fuel")
if fuel then
OldPlayer:saveScore("Fuel", fuel.Value)
end
print("Score saved for " .. OldPlayer.Name)
end
end)
Report Abuse
MARIOSTAR6464 is not online. MARIOSTAR6464
Joined: 21 Jul 2008
Total Posts: 13674
11 Aug 2011 12:44 PM
OldPlayer:saveScore()

Cannot be done.
saveScore() is not a method, which means it's not a vald member of player.

saveScore() is actually me calling a function.
Report Abuse
bballer13sn is not online. bballer13sn
Joined: 03 Jun 2009
Total Posts: 2490
11 Aug 2011 12:46 PM
Than this:

game.Players.PlayerRemoving:connect(function(OldPlayer)
print("Attempting to save score for " .. OldPlayer.Name)
local stats = OldPlayer:FindFirstChild("leaderstats")
if stats then
local cash = stats:FindFirstChild("Cash")
if cash then
saveScore(OldPlayer, cash.Value, "Cash")
end
local level = stats:FindFirstChild("Level")
if level then
saveScore(OldPLayer, level.Value, "Level)
end
local fuel = OldPlayer:FindFirstChild("Fuel")
if fuel then
saveScore(OldPlayer, fuel.Value, "Fuel")
end
print("Score saved for " .. OldPlayer.Name)
end
end)
Report Abuse
bballer13sn is not online. bballer13sn
Joined: 03 Jun 2009
Total Posts: 2490
11 Aug 2011 12:49 PM
Wait, no, this:

game.Players.PlayerRemoving:connect(function(OldPlayer)
print("Attempting to save score for " .. OldPlayer.Name)
local stats = OldPlayer:FindFirstChild("leaderstats")
if stats then
local cash = stats:FindFirstChild("Cash")
if cash then
saveScore(OldPlayer, "Cash", cash.Value)
end
local level = stats:FindFirstChild("Level")
if level then
saveScore(OldPLayer, "Level", level.Value)
end
local fuel = OldPlayer:FindFirstChild("Fuel")
if fuel then
saveScore(OldPlayer, "Fuel", fuel.Value)
end
print("Score saved for " .. OldPlayer.Name)
end
end)
Report Abuse
MARIOSTAR6464 is not online. MARIOSTAR6464
Joined: 21 Jul 2008
Total Posts: 13674
11 Aug 2011 12:51 PM
Thu Aug 11 18:49:50 2011 - Workspace.Points:2: attempt to call method 'WaitForDataReady' (a nil value)
Thu Aug 11 18:49:50 2011 - Script "Workspace.Points", Line 2 - global saveScore
Thu Aug 11 18:49:50 2011 - Script "Workspace.Points", Line 76
Thu Aug 11 18:49:50 2011 - stack end
Thu Aug 11 18:49:50 2011 - Disconnected event because of exception









function saveScore(player, score)
player:WaitForDataReady() --NIL VALUE?
player:SaveNumber("Cash", score)
player:SaveNumber("Level", score)
player:SaveNumber("Fuel", score)
end


function loadScore(player, Counter)
player:WaitForDataReady()
local score = player:LoadNumber("Cash")
local score2 = player:LoadNumber("Level")
local score3 = player:LoadNumber("Fuel")

if score ~= 0 then
Counter.Value = score
Counter.Value = score2
Counter.Value = score3
else
print("Nothing to load/score was 0")
end

end





game.Players.PlayerAdded:connect(function(Player)
local Leaderstats = Instance.new("IntValue")
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = Player

local Points = Instance.new("IntValue", Player)
Points.Name = "TestPoints"
Points.Value = 0

local Fuel = Instance.new("IntValue", Player)
Fuel.Name = "Fuel"
Fuel.Value = 0

local Cash = Instance.new("IntValue", Leaderstats)
Cash.Name = "Cash"
Cash.Value = 0

local Level = Instance.new("IntValue", Leaderstats)
Level.Name = "Level"
Level.Value = 1

Player:WaitForDataReady()
loadScore(Player, Cash)
loadScore(Player, Level)
loadScore(Player, Fuel)

--IGNORE THIS PART
local OneHundred = 100
local RealPoints = 0
local OldPoints = Player.TestPoints.Value
Player.TestPoints.Changed:connect(function(Val)
RealPoints = RealPoints + (Val - OldPoints)
OldPoints = Val
if RealPoints >= 100 then
RealPoints = RealPoints - 100
Level.Value = Level.Value + 1
end
end)
end)
---------

game.Players.PlayerRemoving:connect(function(OldPlayer)
print("Attempting to save score for " .. OldPlayer.Name)
local stats = OldPlayer:FindFirstChild("leaderstats")
if stats then
local cash = stats:FindFirstChild("Cash")
if cash then
saveScore("Cash", cash.Value)
print("Cash saved")
local level = stats:FindFirstChild("Level")
if level then
saveScore("Level", level.Value)
print("Level saved")
local fuel = OldPlayer:FindFirstChild("Fuel")
if fuel then
OldPlayer:saveScore("Fuel", fuel.Value)
print("Fuel saved")
print("Score saved for " .. OldPlayer.Name)
end
end
end
end
end)
Report Abuse
bballer13sn is not online. bballer13sn
Joined: 03 Jun 2009
Total Posts: 2490
11 Aug 2011 12:52 PM
How is that a 'nil value'?
Report Abuse
MARIOSTAR6464 is not online. MARIOSTAR6464
Joined: 21 Jul 2008
Total Posts: 13674
11 Aug 2011 12:53 PM
I'll ake it out and see what happens.
Report Abuse
bballer13sn is not online. bballer13sn
Joined: 03 Jun 2009
Total Posts: 2490
11 Aug 2011 12:54 PM
'ake' it out?
Report Abuse
MARIOSTAR6464 is not online. MARIOSTAR6464
Joined: 21 Jul 2008
Total Posts: 13674
11 Aug 2011 12:59 PM
Typo, besides, it now tells me SaveNumber is a nil value.
Report Abuse
bballer13sn is not online. bballer13sn
Joined: 03 Jun 2009
Total Posts: 2490
11 Aug 2011 01:00 PM
Wow...Really?
Report Abuse
bballer13sn is not online. bballer13sn
Joined: 03 Jun 2009
Total Posts: 2490
11 Aug 2011 01:01 PM
Wait, I just checked the Wiki. This is the correct script:

game.Players.PlayerRemoving:connect(function(OldPlayer)
print("Attempting to save score for " .. OldPlayer.Name)
local stats = OldPlayer:FindFirstChild("leaderstats")
if stats then
local cash = stats:FindFirstChild("Cash")
if cash then
OldPlayer:saveScore("Cash", cash.Value)
end
local level = stats:FindFirstChild("Level")
if level then
OldPlayer:saveScore("Level", level.Value)
end
local fuel = OldPlayer:FindFirstChild("Fuel")
if fuel then
OldPlayer:saveScore("Fuel", fuel.Value)
end
print("Score saved for " .. OldPlayer.Name)
end
end)
Report Abuse
MARIOSTAR6464 is not online. MARIOSTAR6464
Joined: 21 Jul 2008
Total Posts: 13674
11 Aug 2011 01:02 PM
Can't be, OldPlayer:saveScore --Invalid method
Report Abuse
bballer13sn is not online. bballer13sn
Joined: 03 Jun 2009
Total Posts: 2490
11 Aug 2011 01:03 PM
Read the Wiki then. You'll see I'm correct.
Report Abuse
MARIOSTAR6464 is not online. MARIOSTAR6464
Joined: 21 Jul 2008
Total Posts: 13674
11 Aug 2011 01:05 PM
saveScore() is not a method, it is just a function I am calling.
Report Abuse
bballer13sn is not online. bballer13sn
Joined: 03 Jun 2009
Total Posts: 2490
11 Aug 2011 01:06 PM
Mario, if you continue to argue with me about this fact, then you'll never get your DP working. Go test it, then come back to me.
Report Abuse
MARIOSTAR6464 is not online. MARIOSTAR6464
Joined: 21 Jul 2008
Total Posts: 13674
11 Aug 2011 01:10 PM
Man, I am being told something incorrect and then having it forced upon me that I am wrong.

saveScore() is ME calling a FUNCTION.
It IS NOT a METHOD.

I'm starting to get aggrivated.
Report Abuse
bballer13sn is not online. bballer13sn
Joined: 03 Jun 2009
Total Posts: 2490
11 Aug 2011 01:13 PM
I know it is not a method, Mario...Please, listen to me. I've made a WORKING DP LEADERBOARD BEFORE. I AM READING IT RIGHT NOW! I am correct. If you want me to, I can post it in a reply to this thread.
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