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

Why does the server not save this transaction?

Asked by 2 years ago

For context, this is a local script that's placed inside of a button. At first, the transaction goes through successfully, but if the player rejoins, the stats get reverted back to what they were.

local play = script.Parent.Parent.Parent.Parent.Parent.Parent -- Workspace

script.Parent.MouseButton1Down:connect(function()
    if play.leaderstats.Coins.Value >= 100 then
        play.leaderstats.Coins.Value = play.leaderstats.Coins.Value - 100
        play.leaderstats.Tokens.Value = play.leaderstats.Tokens.Value + 1
    end
end)

1 answer

Log in to vote
0
Answered by 2 years ago

You shouldn't use Clients to make your Economy at all. The client cannot be trusted, and it's not secure. And the reason why it's not saving is because you're using a client, if you're using Datastores, the Datastores only take inputs from the server, they don't take inputs from the Client.

Also, you don't need to define workspace, Roblox already did it for you: workspace

Golden Rule: NEVER trust the Client.

A way to go about this is to send a Remote Event request from the Client > Server, then the Server performs a sanity-check, then processes the Transaction.

Example

Client:

RemoteEvent:FireServer(100, Player2) -- // This wouldn't be so secure, just an example.

Server:

RemoteEvent.OnServerEvent:Connect(function(plr, amount, plrToTransfer)
    if game.Players:FindFirstChild(plrToTransfer) then
        if plr.leaderstats.Cash >= amount then
            plr.leaderstats.Cash -= amount
            plrToTransfer.leaderstats.Cash += amount
        end 
    end
end)
Ad

Answer this question