Touch event on a button can u help?

hey i want a touch event but it stays touched if a player stands on it but it doesn’t work

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 
return nil 
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*m.Value*p.Value -- the multiplier you want
Door.BrickColor ="Maroon")
Door.BrickColor ="Maroon")
debounce = false 
else debounce = false 


connection = Door.Touched:connect(onTouched)

Well, If I’m correct, Change local players = game.Players:children() (Line 4)


local players = game.Players:GetChildren()

i changed it but it still doesnt work

Hey, sorry for the late response but if you use the line ‘local’ it will only load locally but mostly when this happens it only loads from what you uploaded in roblox studio, so you gotta make them not local

so for example:

Bad: local stats =player:findfirstchild('leaderstats')

Good: stats = player:FindFirstChild('leaderstats')`

Hope this works! Even though it’s probably completely useless now!