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

data wont save or load? datastoreservice

Asked by 5 years ago

hi, i tried to make a save system for money in my game, but it doesnt want to load or save, ive made some prints to see if the script breaks or doesnt go further but it prints everything out, it also doesnt print out any errors in the output, ive enabled API access and im testing it in the game and not in studio just to make that clear.

Script (located in serverscriptservice)

local DSS = game:GetService("DataStoreService")

local DStore = DSS:GetDataStore("BGPDStore")

game.Players.PlayerAdded:Connect(function(player)
    local Folder = Instance.new("Folder", game.ReplicatedStorage.PlayerValues)
    Folder.Name = player.UserId
    local Money = Instance.new("IntValue", game.ReplicatedStorage.PlayerValues:FindFirstChild(player.UserId))
    Money.Name = "Money"

    Money.Value = DStore:GetAsync(tostring(player.UserId))

    print("PlayerData loaded and updated")

end)

game.Players.PlayerRemoving:Connect(function(player)
    print("player leaving")

    DStore:SetAsync(tostring(player.UserId), game.ReplicatedStorage.PlayerValues:FindFirstChild(player.UserId).Money.Value)
    print("player data saved")

    game.ReplicatedStorage.PlayerValues:FindFirstChild(player.UserId):Destroy()
end)

Local script (located under a GUI in starter GUI)

plrGUI = script.Parent.Parent
plrID = game.Players.LocalPlayer.UserId

game.ReplicatedStorage.PlayerValues:FindFirstChild(plrID).Money.Changed:Connect(function()
    script.Parent.Frame.MoneyText.Text = "Money: "..game.ReplicatedStorage.PlayerValues:FindFirstChild(plrID).Money.Value
end)

script.Parent.Frame.ImageButton.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.PlayerValues:FindFirstChild(plrID).Money.Value = game.ReplicatedStorage.PlayerValues:FindFirstChild(plrID).Money.Value + 5
end)
0
In your playerAdded function: What happens if the datastore fails to load? What happens if the player does not have data in the datastore? You need to add cases for that in your script: royaltoe 5144 — 5y
0
how do i do that? misterviggo 61 — 5y

Answer this question