Touched + TouchedEnded event acting weirdly

I’m trying to make an automatic sliding door, but the touched and untouched events keep acting up weirdly and I’m not sure why. I tried searching for similar issues but couldn’t find any.

Here is the code;

local open = false
local left = script.Parent.Parent.LeftDoor
local right = script.Parent.Parent.RightDoor
local leftfake = script.Parent.Parent.LeftFake
local rightfake = script.Parent.Parent.RightFake
local leftorigin = script.Parent.Parent.LeftOriginal
local rightorigin = script.Parent.Parent.RightOriginal

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if open == false then
			local tween = game:GetService("TweenService")
			local info = TweenInfo.new(1, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out, 0, false, 0)
			local leftt = tween:Create(left, info, {Position = leftfake.Position})
			local rightt = tween:Create(right, info, {Position = rightfake.Position})
			leftt:Play()
			rightt:Play()
			leftt.Completed:Wait()
			wait(.1)
			open = true
		end
	end
end)

script.Parent.TouchEnded:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if open == true then
			local tween = game:GetService("TweenService")
			local info = TweenInfo.new(1, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out, 0, false, 0)
			local leftt = tween:Create(left, info, {Position = leftorigin.Position})
			local rightt = tween:Create(right, info, {Position = rightorigin.Position})
			leftt:Play()
			rightt:Play()
			leftt.Completed:Wait()
			wait(.1)
			open = false
		end
	end
	
end)

And here is what happens when I play;

1 Like
wait(.1)

get rid of this as it is unnecessary, it just keep playing the tweens over and over so many times inside that 0.1 second

Fixed it a bit, but still does this weird thing;

You dont have any cooldown in your door. Do a local variable called “busy” and use it as cooldown when opening. Its breaking it also roblox touchended and touch are really weird and broken. Recommend making it autoclose after a while.

add a delay when returning the doors back to their place inside the .TouchEnded function

1 Like

This worked, thank you! misulinkaobecna1’s solution already exists in my scripts, but it’s smart too

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.