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: Data Persistance being annoying as ususal

Previous Thread :: Next Thread 
DracoTheSecond is not online. DracoTheSecond
Joined: 07 Nov 2011
Total Posts: 859
31 Aug 2013 11:36 AM
Hey everyone,

I'm having Data Persistance problems.

When I test my place in Studio by starting a server, the stats work fine. But when I play it on Roblox like it's a normal game, it set's all my stats to 0.

Why?!?!
Report Abuse
sloppylego87 is not online. sloppylego87
Joined: 25 Mar 2011
Total Posts: 326
31 Aug 2013 11:42 AM
The script must something to do with the game. Solo mode is a mystery. some tools can only be used on solo. I know it might suck but please list the script... I might help.
Report Abuse
Xtreme101 is not online. Xtreme101
Joined: 03 Jan 2009
Total Posts: 4385
31 Aug 2013 11:42 AM
Another invisible script...
Report Abuse
sloppylego87 is not online. sloppylego87
Joined: 25 Mar 2011
Total Posts: 326
31 Aug 2013 11:46 AM
Correct
Report Abuse
sloppylego87 is not online. sloppylego87
Joined: 25 Mar 2011
Total Posts: 326
31 Aug 2013 11:47 AM
How many functions are you using?
Report Abuse
DracoTheSecond is not online. DracoTheSecond
Joined: 07 Nov 2011
Total Posts: 859
31 Aug 2013 04:39 PM
function onXPChanged(player, XP, level)
if XP.Value>=level.Value * 100 and level.Value < script.LevelCap.Value then
XP.Value = XP.Value - level.Value * 100
level.Value = level.Value + 1
end
end

function onLevelUp(player, XP, level)
if player.Character~=nil then
for i = 1,5 do
local fireworks = Instance.new("Part")
fireworks.Shape = 0
fireworks.formFactor = "Symmetric"
fireworks.Size = Vector3.new(1,1,1)
fireworks.BrickColor = BrickColor.Random()
fireworks.CFrame = player.Character.Head.CFrame + Vector3.new(0,2,0)
fireworks.Parent = game.Workspace
game:GetService("Debris"):AddItem(fireworks, 2)
fireworks.Velocity = Vector3.new(math.random(-30,30),math.random(-30,30),math.random(-30,30))
end
end
end

function saveScore(player, score)
player:SaveNumber("Lvl", score)
end

function saveScore2(player, score)
player:SaveNumber("XP", score)
end

function saveScore3(player, score)
player:SaveNumber("Gold", score)
end

function saveScore4(player, score)
player:SaveNumber("Houses", score)
end

function saveScore5(player, score)
player:SaveNumber("Soldiers", score)
end

function loadScore(player, clickCounter)
local score = player:LoadNumber("Lvl")

if score ~= 1 then
clickCounter.Value = score
else
print("Nothing to load/score was 0")
end

end

function loadScore2(player, clickCounter)
local score = player:LoadNumber("XP")

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

end

function loadScore3(player, clickCounter)
local score = player:LoadNumber("Gold")

if score ~= 10 then
clickCounter.Value = score
else
print("Nothing to load/score was 0")
end

end

function loadScore4(player, clickCounter)
local score = player:LoadNumber("Houses")

if score ~= 1 then
clickCounter.Value = score
else
print("Nothing to load/score was 0")
end

end

function loadScore5(player, clickCounter)
local score = player:LoadNumber("Soldiers")

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

end

function onPlayerEntered(newPlayer)



local stats = Instance.new("IntValue")
stats.Name = "leaderstats"

local clicks = Instance.new("IntValue")
clicks.Name = "Lvl"
clicks.Value = 1

local clicks2 = Instance.new("IntValue")
clicks2.Name = "XP"
clicks2.Value = 0

local clicks3 = Instance.new("IntValue")
clicks3.Name = "Gold"
clicks3.Value = 0

local Houses = Instance.new("IntValue")
Houses.Name = "Houses"
Houses.Value = 1

local Soldiers = Instance.new("IntValue")
Soldiers.Name = "Soldiers"
Soldiers.Value = 0

clicks.Parent = stats
clicks2.Parent = newPlayer
clicks3.Parent = stats
Houses.Parent = newPlayer
Soldiers.Parent = newPlayer
stats.Parent = newPlayer

clicks2.Changed:connect(function() onXPChanged(newPlayer, clicks2, clicks) end)
clicks.Changed:connect(function() onLevelUp(newPlayer, clicks2, clicks) end)

newPlayer:WaitForDataReady() -- IMPORTANT: after player.DataReady = true, it won't become false again. You need DataReady to be true for a player before you can load or save data.

-- try loading the player's score
loadScore(newPlayer, clicks)
loadScore2(newPlayer, clicks2)
loadScore3(newPlayer, clicks3)
loadScore4(newPlayer, Houses)
loadScore5(newPlayer, Soldiers)

newPlayer.CharacterAdded:connect(function(c)
c.Humanoid.MaxHealth = newPlayer.leaderstats.Lvl.Value * 10 + 100
c.Humanoid.Health = newPlayer.leaderstats.Lvl.Value * 10 + 100
end)
end

function onPlayerRemoving(player)
print("Attempting to save score for " .. player.Name)
local stats = player:FindFirstChild("leaderstats")
if (stats ~= nil) then
local clicks = stats:FindFirstChild("Lvl")
local clicks2 = stats.Parent:FindFirstChild("XP")
local clicks3 = stats:FindFirstChild("Gold")
local Houses = stats.Parent:FindFirstChild("Houses")
local Soldiers = stats.Parent:FindFirstChild("Soldiers")
if (clicks ~= nil)and(clicks2 ~= nil)and(clicks3 ~= nil)and(Houses ~= nil)and(Soldiers ~= nil) then
saveScore(player, clicks.Value)
saveScore2(player, clicks2.Value)
saveScore3(player, clicks3.Value)
saveScore4(player, Houses.Value)
saveScore5(player, Soldiers.Value)
end
end
end

game.Players.PlayerAdded:connect(onPlayerEntered)
game.Players.PlayerRemoving:connect(onPlayerRemoving)
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