So, i'm making an achievement list, and there is a value which i'm going to make that you earn an achievement when the value gets to 3. When the value changes from 0, I leave, then rejoin, the value goes back to 0. Can anyone explain why this happens?
local DataStore = game:GetService("DataStoreService")
local ds3 = DataStore:GetDataStore("Value2")
game.Players.PlayerAdded:connect(function(player)
wait(1)
local folder = player.BadgeFolder
local badge_1 = Instance.new("IntValue",folder.Badge1)
badge_1.Name = "Badge_1"
badge_1.Value = ds3:GetAsync(player.UserId) or 0
ds3:SetAsync(player.UserId, badge_1.Value)
badge_1.Value.Changed:connect(function()
ds3:SetAsync(player.UserId, badge_1.Value)
end)
end)
game.Players.PlayerRemoving:connect(function(player)
ds3:SetAsync(player.UserId, player.BadgeFolder.Badge1.Badge_1.Value)
end)

1 comment
http://robloxdev.com/articles/Writing-Clean-Code Come back after doing this thanks.