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

[SOLVED] Currency isn't saving after purchase. Can someone help?

Asked by 3 years ago
Edited 3 years ago

So i have a button and when you click it it changes a value to something else. When i rejoin the game the value is the same as it was before but if i change the value through developer console it does save. Please help!

here is the server script inside the button:

local Player = script.Parent.Parent.Parent.Parent.Parent.Parent
local LS = Player:FindFirstChild("leaderstats")
local Button = script.Parent
local Image = script.Parent.Parent
local CharVal = Player:WaitForChild("CharacterValues"):WaitForChild("Jessica")

Button.MouseButton1Click:Connect(function()
    if CharVal.Value == 1 then
        script.Parent.Equip.Disabled = false
        LS.Character.Value = "Jessica"
        Button.Text = "Equipped"

        wait(3)
        script.Parent.Equip.Disabled = true
    elseif CharVal.Value == 0 then
        script.Parent.Purchase.Disabled = false
        CharVal.Value = 1
        LS.Character.Value = "Jessica"
        Button.Text = "Equipped"
        LS.Bucks.Value = LS.Bucks.Value - 300

        wait(3)
        script.Parent.Purchase.Disabled = true
    end
end)

1 answer

Log in to vote
0
Answered by
pwx 1581 Moderation Voter
3 years ago

You are updating the values on the client when the Datastore is on the server. As far as the server is concerned your value stays the same because it does not replicate over. You will need to use a RemoteEvent in order to replicate it over to the server (in which the datastore will then save that value).

0
do i give the currency through the server or local script when using remote event? evil_zebra 4 — 3y
0
The server. pwx 1581 — 3y
Ad

Answer this question