Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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)

1 comment

0

"Currency name is not a valid member of folder" this error appeared

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

This discussion is preserved as it was. New answers, comments, and votes are closed.