I was attempting to learn Data Storage and I was watching a video to help with it and I did exactly as the video told me except I changed the values up a bit... and when I tested the game out on my profile it wouldn't save my wins the following script is under ServerScriptService
and it's in a ServerScript
Please help me out!
local datastore = game:GetService("DataStoreService"):GetDataStore("Wins") game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Model") leaderstats.Name = "leaderstats" leaderstats.Parent = player local wins = Instance.new("IntValue") wins.Value = 0 wins.Name = "Wins" wins.Parent = leaderstats local key = "user_"..player.userId local savedValues = datastore:GetAsync(key) if savedValues then wins.Value = savedValues[1] else local valuesToSave = (wins.Value) datastore:SetAsync(key, valuesToSave) end end) game.Players.PlayerRemoving:connect(function(player) local key = "user_".. player.userId local valuesToSave = (player.leaderstats.Wins.Value) datastore:SetAsync(key, valuesToSave) end)
The next script is the script I put inside of the Part
which gives me wins... I chose a random amount of wins so I can point out that I have a different amount of wins easily....
script.Parent.Touched:connect(function(object) if debounce then return end debounce = true local humanoid = object.Parent:findFirstChild("Humanoid") if humanoid then local player = game.Players:GetPlayerFromCharacter(object.Parent) player.leaderstats.Wins.Value = player.leaderstats.Wins.Value +9765 wait(2) end debounce = false end)
Thank you for reading all the way! I hope you can help me out with this issue!