Hi, I'm trying to make a cash giver for advanced tycoon but I need it to only work once per person so if I use it another person can use it right after but I can't. Sorry if that's confusing help appreciate! Here is the script I have right now what should I change I'm a beginner scripter local ting = 0 --debouncer
function onTouched(hit)
01 | if ting = = 0 then --debounce check |
02 | ting = 1 --activate debounce |
03 | check = hit.Parent:FindFirstChild( "Humanoid" ) --Find the human that touched the button |
04 |
05 | if check ~ = nil then --If a human is found, then |
06 |
07 | local user = game.Players:GetPlayerFromCharacter(hit.Parent) --get player from touching human |
08 | local stats = user:findFirstChild( "leaderstats" ) --Find moneyholder |
09 |
10 | if stats ~ = nil then --If moneyholder exists then |
11 | local cash = stats:findFirstChild( "Cash" ) --Get money |
12 | cash.Value = cash.Value + 100 --increase amount of money by the number displayed here (5000) |
13 | wait( 0 ) |
14 | --wait-time before button works again |
15 | end |
16 |
17 | end |
18 |
19 | ting = 0 --remove debounce |
20 | end |
end
script.Parent.Touched:connect(onTouched)
01 | local users = { } --Empty table |
02 | local debounce = false --A simpler debounce, in my opinion ;) |
03 | function onTouched(hit) |
04 |
05 | if not debounce then --If debounce is false... |
06 | debounce = true --Debounce! |
07 | hum = hit.Parent:FindFirstChild( "Humanoid" ) --Find the human that touched the button |
08 |
09 | if check then --If there's a humanoid |
10 |
11 | local plr = game.Players:GetPlayerFromCharacter(hit.Parent) |
12 | if plr then --If a player touched it, |
13 | local found |
14 | for i, plr_name in pairs (users) do --Loops through the users table |
15 | if plr_name = = plr.Name then --If the entry matches the player's name, |
If there's something you didn't understand, let me know!