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
 

Bool Value Data Persistence.

Previous Thread :: Next Thread 
mark298 is not online. mark298
Joined: 24 Oct 2008
Total Posts: 1264
27 Aug 2012 04:22 AM
I'm working on a Pirate place and on it you buy ships, and when you buy them is Makes a BoolValue with the name of the ship in the stats of the player called 'Ships' to be true. So when you click it and its true, You regen it instead of buying it when it is false.
Now, I edited this Data Persistence script because I wanted it to save your ships but I'm not sure it will work or not.
I tested it on my place but it had all of my Values as True, But I think that may have been because I was testing buying them all.
Can somebody tell me if this would actually work or not though?

function saveScore(player, score)
player:SaveNumber("Dinghy", score)
player:SaveNumber("SailBoat", score)
player:SaveNumber("Caymen", score)
player:SaveNumber("Tentacia", score)
end


function loadScore(player, clickCounter)

local score1 = player:LoadNumber("Dinghy")
local score2 = player:LoadNumber("SailBoat")
local score3 = player:LoadNumber("Caymen")
local score4 = player:LoadNumber("Tentacia")

if score1 ~= false then
clickCounter.Value = score1
else
print("Player doesn't own this!")
end

if score2 ~= false then
clickCounter.Value = score2
else
print("Player doesn't own this!")
end

if score3 ~= false then
clickCounter.Value = score3
else
print("Player doesn't own this!")
end

if score4 ~= false then
clickCounter.Value = score4
else
print("Player doesn't own this!")
end
end

function onPlayerEntered(newPlayer)
local stats = Instance.new("ObjectValue")
stats.Name = "Ships"

local click1 = Instance.new("BoolValue")
click1.Name = "Dinghy"
click1.Value = false
click1.Parent = stats

local click2 = Instance.new("BoolValue")
click2.Name = "SailBoat"
click2.Value = false
click2.Parent = stats

local click3 = Instance.new("BoolValue")
click3.Name = "Caymen"
click3.Value = false
click3.Parent = stats

local click4 = Instance.new("BoolValue")
click4.Name = "Tentacia"
click4.Value = false
click4.Parent = stats

stats.Parent = newPlayer
newPlayer:WaitForDataReady()

loadScore(newPlayer, click1)
loadScore(newPlayer, click2)
loadScore(newPlayer, click3)
loadScore(newPlayer, click4)
end

function onPlayerRemoving(player)
print("Attempting to save score for " .. player.Name)
local stats = player:FindFirstChild("Ships")
if (stats ~= nil) then
local click1 = stats:FindFirstChild("Dinghy")
local click2 = stats:FindFirstChild("SailBoat")
local click3 = stats:FindFirstChild("Caymen")
local click4 = stats:FindFirstChild("Tentacia")
if (click1 ~= nil) then
saveScore(player, click1.Value)
end
if (click2 ~= nil) then
saveScore(player, click2.Value)
end
if (click3 ~= nil) then
saveScore(player, click3.Value)
end
if (click4 ~= nil) then
saveScore(player, click4.Value)
end
end
end

game.Players.PlayerAdded:connect(onPlayerEntered)
game.Players.PlayerRemoving:connect(onPlayerRemoving)
Report Abuse
mark298 is not online. mark298
Joined: 24 Oct 2008
Total Posts: 1264
27 Aug 2012 05:52 AM
It seems that when you enter it puts the Values of the BoolValues as 'true'
Can anybody fix this?
Report Abuse
theuntimelydoctor is not online. theuntimelydoctor
Joined: 30 Jun 2011
Total Posts: 718
27 Aug 2012 06:00 AM
when I look at output it says this if it helps logging probability 0.91998046815394
not logging
06:51:08.199 - attempt to call a nil value
06:51:08.201 - Disconnected event because of exception
Report Abuse
theuntimelydoctor is not online. theuntimelydoctor
Joined: 30 Jun 2011
Total Posts: 718
27 Aug 2012 06:02 AM
srry wrong thread whoops.
Report Abuse
mark298 is not online. mark298
Joined: 24 Oct 2008
Total Posts: 1264
27 Aug 2012 06:04 AM
Oops, I forgot to add:
stats.Parent = newPlayer
Report Abuse
mark298 is not online. mark298
Joined: 24 Oct 2008
Total Posts: 1264
27 Aug 2012 06:57 AM
I've still got the problem of it putting the BoolValues as being true when they should be false, Unless you've bought them in a previouse game and then game back.
Report Abuse
mark298 is not online. mark298
Joined: 24 Oct 2008
Total Posts: 1264
27 Aug 2012 08:39 AM
Bump?
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