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

The datastore wont change it's value to the leaderstats value, why?

Asked by
CL4VIN 9
4 years ago

I was using a bunch of different datastore scripts, none of them worked and I was stumped, I decided to use the Alvinblox one and it didn't work, I went into the console and saw that the datastore was set to the right value, but it wasn't changing the leaderstats to that value.

local DataStoreService = game:GetService("DataStoreService")

local myDataStore = DataStoreService:GetDataStore("myDataStore")

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local cash = Instance.new("IntValue")
    cash.Name = "Dollaroos"
    cash.Parent = leaderstats

    local data
    local success, errormessage = pcall(function()
        data = myDataStore:GetAsync(player.UserId.."-cash")
    end)

    if success then
        cash.Value = data
    else
        print("There was an issue saving your data")
        warn(errormessage)
    end
end)

game.Players.PlayerRemoving:Connect(function(player)

    local success, errormessage = pcall(function()
        myDataStore:SetAsync(player.UserId.."-cash",player.leaderstats.Dollaroos.Value)
    end)

    if success then
        print("Player Data Successfully Saved!")
    else 
        print("There was an error when saving data")
        warn(errormessage)
    end

end)

all I did was modify his script because I didn't want to break it.

0
are you changing the actual server side's stat not just the client side's 0msh 333 — 4y
0
See, I'm not entirely sure... how would I change the server side stat? CL4VIN 9 — 4y
0
basically is this a normal script or a local script jediplocoon 877 — 4y
0
Normal CL4VIN 9 — 4y
View all comments (4 more)
0
And it's inside server script service CL4VIN 9 — 4y
0
To change the value on the server click on the 'Current' on the home tab at the top of your screen(while playing). It should say 'Current: Client', once you click it, it will take you to the Server Side, then go to Players, your player and change the value of your cash and see if it saves when you stop and play again. xInfinityBear 1777 — 4y
0
Alright, thanks. CL4VIN 9 — 4y
0
Ok, it works. The issue was the way I was adding to the value... My suspicion was right. How am I supposed to make it so that you click on something and it adds it through the server? CL4VIN 9 — 4y

Answer this question