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: Save Script For One Stat

Previous Thread :: Next Thread 
Drybones3363 is not online. Drybones3363
Joined: 16 Aug 2013
Total Posts: 1547
24 Dec 2013 07:42 AM
This won't work...
function enter(player)
wait()
player:WaitForDataReady()
repeat wait() until player:FindFirstChild("leaderstats")
if player.DataReady then
if player:findFirstChild("leaderstats") then
local score = player.leaderstats:FindFirstChild("Points")
for i = 1,#score do
local ScoreLoaded = player:LoadNumber(0.5*score[i].Name)
wait()
if ScoreLoaded ~= 0 then
score[i].Value = ScoreLoaded
end
end
end
end
end

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

game.Players.PlayerAdded:connect(enter)
game.Players.PlayerRemoving:connect(leave)
Report Abuse
Drybones3363 is not online. Drybones3363
Joined: 16 Aug 2013
Total Posts: 1547
24 Dec 2013 08:32 AM
bump
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
24 Dec 2013 08:34 AM
Won't save or it won't load?
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
24 Dec 2013 08:34 AM
Also you're supposed to wait for data ready when leaving.
Report Abuse
Drybones3363 is not online. Drybones3363
Joined: 16 Aug 2013
Total Posts: 1547
24 Dec 2013 08:36 AM
what do you mean by that?
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
24 Dec 2013 08:37 AM
function leave(player)
if player:findFirstChild("leaderstats") then
player:WaitForDataReady() --That's what I mean, both entering and leaving you're supposed to wait for data ready.
local score = player.leaderstats:FindFirstChild("Points")
for i = 1,#score do
player:SaveNumber(score[i].Name,score[i].Value)
end
end
end
Report Abuse
Drybones3363 is not online. Drybones3363
Joined: 16 Aug 2013
Total Posts: 1547
24 Dec 2013 08:39 AM
oh yeah, i see
Report Abuse
darthpyro is not online. darthpyro
Joined: 18 Aug 2009
Total Posts: 3569
24 Dec 2013 08:41 AM
I wouldn't save when they leave, PlayerRemoving is unreliable and it may not be able to fire the entire script before they're gone.
Report Abuse
Drybones3363 is not online. Drybones3363
Joined: 16 Aug 2013
Total Posts: 1547
24 Dec 2013 08:41 AM
function enter(player)
wait()
player:WaitForDataReady(0.5)
repeat wait(0.1) until player:FindFirstChild("leaderstats")
if player.DataReady then
if player:findFirstChild("leaderstats") then
local score = player.leaderstats:FindFirstChild("Points")
for i = 1,#score do
local ScoreLoaded = player:LoadNumber(0.5*score[i].Name)
wait(0.1)
if ScoreLoaded ~= 0 then
score[i].Value = ScoreLoaded
end
end
end
end
end

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

game.Players.PlayerAdded:connect(enter)
game.Players.PlayerRemoving:connect(leave)

I used this and it doesn't work...
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
24 Dec 2013 08:46 AM
function enter(player)
wait()
player:WaitForDataReady()
repeat wait(0.1) until player:FindFirstChild("leaderstats")
if player.DataReady then
if player:findFirstChild("leaderstats") then
local score = player.leaderstats:FindFirstChild("Points")
for i = 1,#score do
local ScoreLoaded = player:LoadNumber(0.5*score[i].Name)
wait(0.1)
if ScoreLoaded ~= 0 then
score[i].Value = ScoreLoaded
end
end
end
end
end

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

game.Players.PlayerAdded:connect(enter)
game.Players.ChildRemoved:connect(leave)

I recommend you have a button for saving because childremoved and playerremoving are not reliable.
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