Keep door open if player is still in trigger box

They worked, the one in my post. It opened and closed the door, but I want it to stay open if the player is still in the tirgger box.

According to my knowledge, Touched had already done that for you. It kinda just stays open when you’re still in that part.

But how do I make it close if the player is out of the hitbox?

TouchEnded had done that for you, again. When you get out of the part, it closes.

i would use Zone+ then do something like

local ZoneM = require(path)
local NewZ = ZoneM.new(area) -- eg the hitbox surrounding the door

NewZ.playerEntered:Connect(function(player)
       --Open door
end)

NewZ.playerExited:Connect(function(player)
       --Close door
end)



Also… make your hit box taller, so that it will detect the player’s HumanoidRootPart

1 Like

The script you sent me didn’t do that. It didn’t close again.

Already did, but changed nothing :confused:

Look to the code I posted on that link. The person had the same issue, detecting when entering and leaving a hit box

I think you need to determine if the issue is your detecting hitboxes correctly or if its a problem with the mechanic of the door opening and closing.

maybe use some print statements that print “Open” and “Close” to make sure the hitbox stuff works first. Then if it does, but doors not opening or closing properly, then work on the mechanic of the doors

Are you sure you’re going in the hitbox and then exiting the hitbox back and fourth (at a fast pace)? If so, must’ve been 2 tweens (in one part) are playing at the same time, which you know, break the tweens.

The script I’m using is the one you sent me. This is what happens in video:

And this is the script you gave me:

local model = script.Parent

local trigger_in = model.Trigger_In


local left = model.MainL

local right = model.MainR


local activated = false


local TweenService = game:GetService("TweenService")


local tweenInfo = TweenInfo.new(



	model.Speed.Value, --Time

	Enum.EasingStyle.Bounce, --Easing Style

	Enum.EasingDirection.Out, --EasingDirection

	0, --Repeat Count

	false, --Reverse

	0 --DelayTime



)


local function open(hitPart)

	local player = game.Players:GetPlayerFromCharacter(hitPart.Parent)

	if player and activated == false then

		activated = true


		local tweenL = TweenService:Create(left, tweenInfo, {Position = model.TargetL.Position})

		local tweenR = TweenService:Create(right, tweenInfo, {Position = model.TargetR.Position})



		tweenL:Play()

		tweenR:Play()

		tweenR.Completed:Wait()
	end
end

local function close(hitPart)
	local player = game.Players:GetPlayerFromCharacter(hitPart.Parent)
	if player and activated == true then
		activated = false
		--Create the Tween closing animation by yourself.
	end
end

trigger_in.Touched:Connect(open)
trigger_in.TouchEnded:Connect(close)

I forgot there’s a Completed event in the function. Remove that.
Weird, if that’s the case, then I’ll try to do something.

As I said, put some print statements or breakpoints to make sure its getting into that ‘close’ funcion

1 Like

…Are you sure that you made both closing tweens? Because I just took a glance and there isn’t any?

I get this

I put print statements in the activated and I get this.

There isn’t a tween for closing, I’m not sure how to do that. The tween for opening goes to target L and Target R. How do I tween it to go back to its original position?

Well, make 2 parts and put both of them inside the doors. It should be getting you the original position. Then you can tween it using those 2 parts. Oh, make sure it is transparent and non-collidable. I mean, we wouldn’t like parts being visible and blocking the door entrance, right?

(PS: I thought CFrame was gonna work, but I guess not, since Position kind of overrides it.)

Here is from my own door’s code

local tweenInfo = TweenInfo.new(
	1,
	Enum.EasingStyle.Quart,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

local tweenOpenRight = game.TweenService:Create(motorRight,tweenInfo,{TargetAngle=100})
local tweenOpenLeft = game.TweenService:Create(motorLeft,tweenInfo,{TargetAngle=100})
local tweenCloseRight = game.TweenService:Create(motorRight,tweenInfo,{TargetAngle=0})
local tweenCloseLeft = game.TweenService:Create(motorLeft,tweenInfo,{TargetAngle=0})

		tweenOpenRight:Play()
		tweenOpenLeft:Play()
		tweenOpenRight.Completed:Wait()


		tweenCloseRight:Play()
		tweenCloseLeft:Play()
		tweenCloseRight.Completed:Wait()

Can I use CFrame instead. I don’t like this tween