As the title says, how do I make the door remain open if the player is still in triggerbox?
local model = script.Parent
local trigger_in = model.Trigger_In
local trigger_out = model.Trigger_Out
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
true, --Reverse
0 --DelayTime
)
local function open(otherPart)
local player = game.Players:FindFirstChild(otherPart.Parent.Name)
if player and not activated 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()
activated = false
end
end
trigger_in.Touched:Connect(open)
trigger_out.Touched:Connect(open)
local trigger_in = model.Trigger_In
local trigger_out = model.Trigger_Out
didnāt test it but maybe this could work better. using only one part to trigger your tween and creating another tween info for the closing tween instead of trying to reverse it
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()
trigger_in.TouchEnded:Connect(function()
activated = false
-- close doors
end)
end
end
trigger_in.Touched:Connect(open)
Why putting TouchEnded function INSIDE the open function?! Try this code instead:
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 am very sorry if I criticizes you too harsh. The script you gave were kind of, redundant?)
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)
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)