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

clicking give money every 3 seconds? does not work?

Asked by
Filipalla 504 Moderation Voter
7 years ago
Edited 7 years ago
local debounce = false
local player = game.Players.LocalPlayer

function ButtonPress()
if debounce == false then
debounce = true
-- PUT THE THING YOU WANT TO HAPPEN v
player.leaderstats.Money.Value = player.leaderstats.Money.Value + 10
wait(3)
debounce = false
end
end

script.Parent.ClickDetector.MouseClick:connect(ButtonPress)

i want it to give money ween clicking but only every 3 seconds why did this not work?

2
Because LocalPlayer does not work in ServerScripts. ClickDetector will provide you with the player who clicked on the brick, use that to define player. M39a9am3R 3210 — 7y

1 answer

Log in to vote
1
Answered by
StoIid 364 Moderation Voter
7 years ago
Edited 7 years ago

This is because the script you are using is located in the workspace, under a part. Also it is because the script you are using is probably a Local Script.

If you're going to use a Server Script located under the part, you're going to need to do this:

local debounce = false

script.Parent.ClickDetector.MouseClick:connect(function(plr)
    if debounce == false then 
    print(plr.Name)
    debounce = true
    plr.leaderstats.Legend.Value = plr.leaderstats.Legend.Value + 10
    wait(3)
    debounce = false
end
end)

Explanation:

Whenever you do something or run a function triggered by a player, the first parameter is always the player Pretty sure...might need a vouch on that. Parameters are the things that go inside the parenthesis "()" in code. I think of them as a different kind of variables, which they kinda are.

The player that it gets is the player located in game.Players so there is no need for the line local player = game.Players.LocalPlayers, it also isn't a LocalScript so that wouldn't work at all. Place this script in a ServerScript and put it under the part.

This script should work and I explained what you were doing wrong so if you'd please accept, that'd be awesome!

0
i think you mean script not serverscript Filipalla 504 — 7y
Ad

Answer this question