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: What is wrong with these two save and load scripts?

Previous Thread :: Next Thread 
PumpkinRPG is not online. PumpkinRPG
Joined: 09 Nov 2010
Total Posts: 92
22 Feb 2013 08:26 AM
Save:

function SaveScore(plyr, score)
plyr:SaveNumber("Gold", "Candy", "EXP")
end




function onClicked()

player = script.Parent.Parent.Parent.Parent.Parent
player:WaitForDataReady()
if player.DataReady == true then
SaveScore(player, player.leaderstats:findFirstChild(script.Parent.Parent.Parent.Configuration.Type.Value).Value)
m = Instance.new("Message",player.PlayerGui)
m.Text = script.Parent.Parent.Parent.Configuration.Type.Value.. " Saved"
game:service("Debris"):AddItem(m, 3)
else
m = Instance.new("Message",player.PlayerGui)
m.Text = "Waiting untill DataReady..."
game:service("Debris"):AddItem(m, 3)

end
end

script.Parent.MouseButton1Click:connect(onClicked)


Load:

function loadScore(plyr, clickCounter)

local score = plyr:LoadNumber("EXP", "Level", "Candy")

if not score == 0 then
clickCounter.Value = score
else
print("Error, no loadvalue!")
end

end



function onClicked()


player = script.Parent.Parent.Parent.Parent.Parent
player:WaitForDataReady()
if player.DataReady == true then
loadScore(player, player.leaderstats:findFirstChild(script.Parent.Parent.Parent.Configuration.Type.Value))
player.leaderstats:findFirstChild(script.Parent.Parent.Parent.Configuration.Type.Value).Value = player:LoadNumber("Candy", "EXP", "Level")
m = Instance.new("Message",player.PlayerGui)
m.Text = script.Parent.Parent.Parent.Configuration.Type.Value.. " Loaded"
script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid.Health = 100
game:service("Debris"):AddItem(m, 3)
else
m = Instance.new("Message",player.PlayerGui)
m.Text = "Waiting untill DataReady..."
game:service("Debris"):AddItem(m, 3)
end
end

script.Parent.MouseButton1Click:connect(onClicked)
Report Abuse
bibo5o is not online. bibo5o
Joined: 17 Jan 2009
Total Posts: 414
22 Feb 2013 08:44 AM
--[[Well, one problem might be that you're loading and saving different stats...

Here's a rough outline of what you might want

these are auto's]]

function onPlayerEntered(newPlayer)
newPlayer:WaitForDataReady()
wait(0.5)
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"

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

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

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

Candy.Parent = stats
Gold.Parent = stats
XP.Parent = stats
stats.Parent = newPlayer
newPlayer.leaderstats.Candy.Value = newPlayer:LoadNumber("Candy")
newPlayer.leaderstats.Gold.Value = newPlayer:LoadNumber("Gold")
newPlayer.leaderstats.XP.Value = newPlayer:LoadNumber("XP")
end

function onPlayerLeave(oldPlayer)
oldPlayer:SaveNumber("Candy", oldPlayer.leaderstats.Candy.Value)
oldPlayer:SaveNumber("Gold", oldPlayer.leaderstats.Gold.Value)
oldPlayer:SaveNumber("XP", oldPlayer.leaderstats.XP.Value)
end

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

--And then there's button load and saves. This would have to go in the frame the buttons are in, and you'd also need a leaderstats script

function onPlayerEntered(newPlayer)
newPlayer:WaitForDataReady()
wait(0.5)
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"

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

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

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

Candy.Parent = stats
Gold.Parent = stats
XP.Parent = stats
stats.Parent = newPlayer
newPlayer.leaderstats.Candy.Value = newPlayer:LoadNumber("Candy")
newPlayer.leaderstats.Gold.Value = newPlayer:LoadNumber("Gold")
newPlayer.leaderstats.XP.Value = newPlayer:LoadNumber("XP")
end

function onPlayerLeave(oldPlayer)
oldPlayer:SaveNumber("Candy", oldPlayer.leaderstats.Candy.Value)
oldPlayer:SaveNumber("Gold", oldPlayer.leaderstats.Gold.Value)
oldPlayer:SaveNumber("XP", oldPlayer.leaderstats.XP.Value)
end

script.Parent.Load.MouseButton1Click:connect(onPlayerEntered)
script.Parent.Save.MouseButton1Click:connect(onPlayerLeave)

--Only customizing left c:
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