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 |
|
|
| |
|
|
| 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
|
  |
| 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 |
|
|