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

Is my console lying about data being saved?

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)

2 comments

0

Are you getting the same problem in a server?

0

this happens to me too, i can't find the solution.

1 answer

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

2 comments

0

Hope this helped

0

how would the player exactly load their data in solution 1?

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