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

How to make a text button take away currency after being clicked?

Hello, so basically I made a text button, and I want that text button to take away 500 Points of your leaderstats currency when clicked. Anyone know how?

1 comment

1

My answer to your previous question about paying to teleport is the same concept; all you need to do is remove the teleport bit.

2 answers

Maybe this gonna help

pathtoyourButton.MouseButton1Click:Connect(function()
	Currency = Currency - 500 -- or your code to subtract it
end)

3 comments

0

just like that or u can do Currency -= amount

0

Twice works

0

this is client sided

To remove currency when a button is pressed, You have to create a localscript, a remote event and a script In the localscript, write:

Button.MouseButton1Click:Connect(function() --replace Button with the path to your button
game.ReplicatedStorage.RemoteEvent:FireServer(500) -- replace RemoteEvent with the name -- of your remove event
end)

in the script write:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, amount)
	player.leaderstats['Currency Name Here'] -= amount
end)

If you were to remove the current on the client side, the currency would only get removed for the player. The other players and the server would not detect a change in the currency.

5 comments

0

I kinda understand but what does it mean by "replace remote event by name of my remove event" like what type of thing am i supposed to put there and for the Path to my button, do i put where it is? Can u show an example

0

An example would be: script.Parent.MouseButton1Click:Connect(function()

0

And for the remoteevent thing, create a remote event in replicatedstorage and name it whatever, then in the script and in the localscript, replace the RemoteEvent text with the name of your remote event

0

so do i put " PathWayPoint" instead of button

0

well if the script is in the button, you would do script.parent

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