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 » Scripters
Home Search
 

Re: data store script not finishing?

Previous Thread :: Next Thread 
Raildex is not online. Raildex
Joined: 06 Dec 2009
Total Posts: 934
11 Feb 2016 01:24 PM
so my script here is having a problem when the player leaves. It makes it to the data ready print but then doesnt get any farther than that. Do you see anything wrong that im doing?

local datastore = game:GetService("DataStoreService"):GetDataStore("PlayerStats")
print("cash datastore created")


game.Players.PlayerAdded:connect(function(newPlayer)
print("EnteredGame")
--newPlayer:WaitForDataReady()
print("data ready")
local stats2 = newPlayer:WaitForChild("leaderstats")

stats2.Cash.Value = datastore:GetAsync(newPlayer.userId .. "Cash")
print("Loaded stats")
wait(1)
datastore:SetAsync(newPlayer.userId .. "Cash", stats2.Cash.Value)
print("Saved stats")
end)

game.Players.PlayerRemoving:connect(function(player)
print("ExitedGame")
--player:WaitForDataReady()
print("data ready")
--wait(2)
local stats = player.leaderstats
print("got leaderstats")
datastore:SetAsync(player.userId .. "Cash", stats.Cash.Value)
print("Saved stats")
end)

game.OnClose = function()
print("begin game close")
wait(2)
print("end game close")
end
Report Abuse
128Gigabytes is not online. 128Gigabytes
Joined: 17 Apr 2014
Total Posts: 3616
11 Feb 2016 01:40 PM
Is there any output?
Report Abuse
RulerOfTheFree is not online. RulerOfTheFree
Joined: 11 Mar 2015
Total Posts: 56
11 Feb 2016 02:54 PM
If you put a print between these two,

local stats2 = newPlayer:WaitForChild("leaderstats")
stats2.Cash.Value = datastore:GetAsync(newPlayer.userId .. "Cash")

, it probably won't print. If it doesn't, it's not finding "leaderstats", so you need to create it.
Report Abuse
Raildex is not online. Raildex
Joined: 06 Dec 2009
Total Posts: 934
11 Feb 2016 03:53 PM
The player added function wasnt what was wrong, its the second function. I had already done that
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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