Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does the server not save this transaction?

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

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.