What I’m trying to achieve
I’m trying to do a touched event where it doesn’t print countless times
What I tried
I tried putting a while wait(1) loop and it didn’t work, I also tried adding the hit.Name = “RightFoot” but it didn’t work either
Script
while wait(1) do
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
print("Player touched part")
hit.Parent:MoveTo(Vector3.new(0,100,0))
end
end)
end
Output
Can someone please tell me any solutions or ideas? I need this for a game I’m working on, I would really appreciate it
The issue is you have this in a while loop. So every second you are creating a new connection. Events are allowed to have multiple listeners so that works. Take it out of the while. You don’t need it here.
local debounce = true
while wait(1) do
script.Parent.Touched:Connect(function(hit)
if debounce then
debounce = false
if hit.Parent:FindFirstChild("Humanoid") then
print("Player touched part")
hit.Parent:MoveTo(Vector3.new(0,100,0))
wait(1)
debounce = true
end
end
end)
end