So I'm making a datastore script and the console says the data is saving and loading. I do not understand why the data is still set to 0 when I leave and join.
local data local success, errormessage = pcall(function() data = myDataStore:GetAsync(player.UserId.."-robux") end) if success then robux.Value = data else print("There was an error whilst getting your data") warn(errormessage) end end) game.Players.PlayerRemoving:Connect(function(player) local success, errormessage = pcall(function() myDataStore:SetAsync(player.UserId.."-robux",player.leaderstats.robux.Value) end) if success then print("Player Data successfully saved!") else print("There was an error when saving data") warn(errormessage) end end)
Sometimes the server script grabs the data incorrectly. I had this problem. Two solutions. 1. Make a save gui that when clicked triggers a remote event. Example LocalScript
local remote = game.ReplicatedStorage.Save script.Parent.MouseButton1Click:Connect(function() remote:FireServer(game.Players.LocalPlayer.Robux.Value) end)
Server Script
local remote = game.ReplicatedStorage.Save remote.OnServerEvent:Connect(function(plr, robux) --Save function end)
Solution 2 - Make a local script in playergui. A folder in workspace. Inside the folder, as many "int values" as max players for your game. A ServerScript - Example Server Script -
game.Players.PlayerAdded:Connect(function(plr) game.Workspace.DataFolder.Value.Name = plr.Name end)
Local Script -
while true do wait() game.Workspace:WaitForChild(game.Players.LocalPlayer.Name).Value = game.Players.LocalPlayer.Robux.Value
Saving Script
game.Players.PlayerRemoving:Connect(function(plr) local save = game.Workspace.DataFolder:WaitForChild(plr.Name).Value --Do saving stuff