Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I fix a certain glitch in a datasave script?

Asked by 4 years ago

Hello, I have recently put a "coin system" into my game. This system will save your coins when you leave the game. I am not that advanced at coding so I am following the youtuber "AlvinBlox" for a tutorial. The entire script seems to be working except one tiny part. Here is said script:

game.Players.PlayerRemoving:Connect(function(player)
    local ID = CurrencyName..":"..player.UserId
    DataStore:SetAsync(ID.player.leaderstats.CurrencyName.Value)
    print("Data Saved")

end)

When I leave the game, it says that the player is nil. I suspect that it is because the player is not in the game anymore so the server can't save the progress (I am not sure though). I am simply looking for a fix for this glitch.

2 answers

Log in to vote
0
Answered by 4 years ago
game.Players.PlayerRemoving:Connect(function(player)
    local ID = CurrencyName..":"..player.UserId
    DataStore:SetAsync(ID.player.leaderstats.CurrencyName.Value)
    print("Data Saved")

end)

If you look closely at line 3 it says ID.player it really should be ID, player so this would be the script you would use

game.Players.PlayerRemoving:Connect(function(player)
    local ID = CurrencyName..":"..player.UserId
    DataStore:SetAsync(ID, player.leaderstats.CurrencyName.Value)
    print("Data Saved")

end)
0
"Currency name is not a valid member of folder" this error appeared n00b_warri0r 11 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Nvm I looked at the tutorial again and I had made a mistake.

Answer this question