Hey! So I'm trying to make a very basic coin save and load. It is meant to load the player coins when it enters, and save them when it leaves. However it always saves the coins value as 0, and if I try to just read the coins value from a normal script, it reads it as 0 no matter what value is stored. However if I try to read the value from a LocalScript it does read the value.
What is wrong?
local DataStore = game:GetService("DataStoreService") local ds = DataStore:GetDataStore("CoinsSave") game.Players.PlayerAdded:Connect(function(player) local leader = Instance.new("Folder", player) leader.Name = "leaderstats" local coins = Instance.new("IntValue", leader) coins.Name = "Coins" local success, coinsData = pcall( function() coins.Value = ds:GetAsync(player.UserId, player.leaderstats.Coins.Value) end ) if success then print ("success") else print("Failed") end end) game.Players.PlayerRemoving:Connect(function(player) --print("player left") local success, err = pcall( function() --print("func") print(player.leaderstats.Coins.Value) ds:SetAsync(player.UserId, player.leaderstats.Coins.Value) end ) if success then print("success") else print("Failed") end end)
You are changing the value on the client. You will have to use RemoteEvents or RemoteFunctions to change the value on the server so that it replicates.