Touch event run only one

I have a problem that i want this to make like only touch one time then no more again this is like an obby when u touch one time then the color change and no more again Thank u in advance

 local part = script.Parent
local parts = script.Parent.Parent.Yeay



parts.Touched:Connect(function(hit)
	local plr = hit.Parent:FindFirstChild("Humanoid")
	if plr ~= nil then
		part.BrickColor = BrickColor.new("Really red")
		wait(1)
		part.BrickColor = BrickColor.new("Br. yellowish orange")
	end
end)

you should do something when they leave the part, ex: use parts.TouchEnded:Connect(function(left) and replace all the hit with left and change the colors or whatever you want to do.

1 Like

Try this :

local part = script.Parent
local Touched = false
local parts = script.Parent.Parent.Yeay
   parts.Touched:Connect(function(hit
local plr = hit.Parent:FindFirstChild("Humanoid")
if plr ~= nil and Touched == false then
Touched = true
	part.BrickColor = BrickColor.new("Really red")
	wait(1)
	part.BrickColor = BrickColor.new("Br. yellowish orange")
end
end)
1 Like
local part = script.Parent
local debounce = false
local parts = script.Parent.Parent.Yeay
parts.Touched:Connect(function(hit)
	local plr = hit.Parent:FindFirstChild("Humanoid")
	if plr ~= nil then
		if debounce == false then
			part.BrickColor = BrickColor.new("Really red")
			wait(1)
			part.BrickColor = BrickColor.new("Br. yellowish orange")
			debounce = true
		end
	end
end)```
3 Likes

But he wanted to touch only 1 time, does not mean he wanted the touch event not to spam

that’s what i exactly did, debouncing it so it only happens one time.

2 Likes

Thank u so much ur the best it helps me a lot :slight_smile:

1 Like

If it worked , you can give me solution , it helped me ,also your post shoul go to #help-and-feedback

i dont know how sorry but im trying to find how to do it

1 Like

A better way of doing this would be to disconnect the function.

2 Likes