Log in to vote

How do you add value to a player when gui button clicked?

Asked by 13 days ago
Edited 13 days ago

Ok so im trying to make a gui button for my staff where when they click it, it ads 1000 coins to their stats.

local Button = script.Parent

Button.Touched:Connect(function() local Coins = game.player.Stats.Coins Coins.Value = Coins.Value + 10000 end)

Thats my localscript. If it helps this is what I would put into my dev console to give myself 10000 coins game.Players["IMAO421"].Stats.Coins.Value = 10000

1 answer

Log in to vote
Answered by 13 days ago
Edited 13 days ago

Hello! I will try to help you out.

If we try to change the value by pressing the button, no one else in the server will see it. Only the client will. To fix this, we first need to add a normal script/server script into wokspace. I will name mine Events Inside of that, insert a remote event. I will name mine AddCoins.

Inside the server script type:

    player.leaderstats.Coins.Value += 1000

Very simple. Now that we have done that, we can start coding the local script that you put in the button.

Just type:

local button = script.Parent
local player = game.Players.LocalPlayer
button.Visible = false

local staff = {
    1842291423; -- put the player's id you want to have the button here
    87326472;  -- same thing here.  If you don't have another person, just delete this line.
for i, v in pairs(staff) do
    if player.UserId == v then
        button.Visible = true


if you want everyone to have the button then remove the for loop, the if statement, and line 3 from the Local Script But if you just want certain people to have it, then leave it the way i have it above.

I hope I was able to help you out! If it did, please let me know and also accept this answer please. Let me know if you have any questions!

Thanks! It worked! IMAO421 0 — 13d

Answer this question