hey can someone help me i want it te keep touched it is for a button so people dont need to dance on the button ```lua Door = script.Parent 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 onTouched(hit) if debounce == false then local human = hit.Parent:findFirstChild("Humanoid") if (human == nil) then return end local player = getPlayer(human) debounce = true if (player == nil) then return end local stats = player:findFirstChild("leaderstats") local sp = stats:findFirstChild("Cash") -- replace nani with the stat that is getting removed/subtracted. local ao = stats:findFirstChild("Multi") local a = stats:findFirstChild("Rebirths") local u = stats:findFirstChild("Ultra") local m = stats:findFirstChild("Mega") local p = stats:findFirstChild("Prestige") local o = stats:findFirstChild("Levelc") -- replace nani with the stat that is getting removed/subtracted. if sp == nil then return false end if ao == nil then return false end if (sp.Value >=50) then -- replace 100 with stat cost sp.Value = sp.Value - 50 o.Value = 0 print("Enough Money") ao.Value = ao.Value + 2a.Valuem.Value*p.Value -- the multiplier you want Door.BrickColor = BrickColor.new("Maroon") wait(0) Door.BrickColor = BrickColor.new("Maroon") debounce = false else debounce = false end end
end
connection = Door.Touched:connect(onTouched) ```
local debounce = false -- This was missing. Made your code easier to see 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 onTouched(hit) if debounce == false then local human = hit.Parent:findFirstChild("Humanoid") if (human == nil) then return end -- local player = getPlayer(human) debounce = true if (player == nil) then return end local stats = player:findFirstChild("leaderstats") local sp = stats:findFirstChild("Cash") -- replace nani with the stat that is getting removed/subtracted. local ao = stats:findFirstChild("Multi") local a = stats:findFirstChild("Rebirths") local u = stats:findFirstChild("Ultra") local m = stats:findFirstChild("Mega") local p = stats:findFirstChild("Prestige") local o = stats:findFirstChild("Levelc") -- replace nani with the stat that is getting removed/subtracted. if sp == nil then return false end-- if ao == nil then return false end-- if (sp.Value >=50) then -- replace 100 with stat cost sp.Value = sp.Value - 50 o.Value = 0 print("Enough Money") ao.Value = ao.Value + 2 a.Value = Value * p.Value -- the multiplier you want Door.BrickColor = BrickColor.new("Maroon") wait(0) Door.BrickColor = BrickColor.new("Maroon") debounce = false else debounce = false end end end-- connection = Door.Touched:connect(onTouched)