So i need to make it where, if someone touches a birck. Then a script fires one time, every time the person touches the brick, not wait then do it again

so i tried this

debounce = false
script.Parent.Touched:Connect(function(hit)

local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then 
 if debounce == false then
  debounce = true
  Instance.new("Part", game.Workspace)
  end
  end
 end)
 script.Parent.TouchEnded:Connect(function() wait() debounce = false end)

but i need it to happen one time per when the person touches the block again, how can i make it where it doesn't fire while they walk again, they touch the brick again with the legs. how can i make it only happen once.

Say there are two bricks, if the person touches the scripted brick, it inserts a new part one time, but if they walk to the other brick, it doesn't fire some more while they are walking to the other brick, but have it fire again when they are on the other brick and touch the scripted brick.

Could someone help a little. Thanks so much.

2 comments

0

You don't need TouchEnded. You can simply set it back within the Touched event function.

0

change if debounce = false then to if not debounce then to check if its false