The jist is that every time a player hit this block, one script increases a value in their leaderstats and the other clones and puts a GUI in their playergui (the gui just shows '+10', for the amnt gained)
However, it will only do this once. I am stumped. Why?
GUI cloning script:
local debounce = false function getPlayer(humanoid) local players = game.Players:children() for i = 1, #players do if players[i].Character.Humanoid == humanoid then return players[i] end end return nil end function onTouch(part) local human = part.Parent:findFirstChild("Humanoid") if (human ~= nil) and debounce == false then debounce = true local player = getPlayer(human) if (player == nil) then return end user = game.Players:findFirstChild(human.Parent.Name) local gui= script.Parent.Plus:clone() gui.Parent = player.PlayerGui gui.Frame.Amount.Find.Disabled = false wait(2) else wait(2) debounce = false end end script.Parent.Touched:connect(onTouch)
Cash adding script:
debounce = false function onTouched(part) if debounce == false then local h = part.Parent:findFirstChild("Humanoid") if (h~=nil) then local thisplr = game.Players:findFirstChild(h.Parent.Name) if (thisplr~=nil) then local stats = thisplr:findFirstChild("leaderstats") if (stats~=nil) then debounce = true local cash = stats:findFirstChild("SpeedCoin") if (cash~=nil) then cash.Value = cash.Value+ 10 wait(0.3) debounce = false end end end end end end script.Parent.Touched:connect(onTouched)
The problem is that you included the debounce = false before the end. In this case, if (human ~= nil) and debounce == false then the debounce = false will not run because you've put it after the else statement. To make the script work, you just need to move the debounce = false under one end statement and it will set debounce to false even if (human ~= nil) and debounce == false