Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Is my console lying about data being saved?

Asked by 5 years ago

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)
0
Are you getting the same problem in a server? pidgey 548 — 5y
0
this happens to me too, i can't find the solution. jesusbeef 33 — 5y

1 answer

Log in to vote
0
Answered by
sheepposu 561 Moderation Voter
5 years ago

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
0
Hope this helped sheepposu 561 — 5y
0
how would the player exactly load their data in solution 1? jesusbeef 33 — 5y
Ad

Answer this question