Prompt.Triggered:Connect(function(player)
if IsHiding then return end
--
Prompt.Enabled = false
local Character = player.Character
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
LeftDoorOpenTween:Play()
RightDoorOpenTween:Play()
wait(TweenTime)
HumanoidRootPart.Position = PositionPart.Position -- I do get teleported
LeftDoorCloseTween:Play()
RightDoorCloseTween:Play()
UIS.InputBegan:Connect(function(player) -- doesn't run
print("InputBegan") -- doesn't print
if UIS.InputBegan == Enum.KeyCode.W or UIS.InputBegan == Enum.KeyCode.E or UIS.InputBegan == Enum.KeyCode.S or UIS.InputBegan == Enum.KeyCode.D or UIS.InputBegan == Enum.KeyCode.Space then
if IsHiding then
print("KeyCode was Inputted") -- doesn't print
LeftDoorOpenTween:Play()
RightDoorOpenTween:Play()
HumanoidRootPart.Position = PromptPart.Position
IsHiding = false
Prompt.Enabled = true
wait(TweenTime)
LeftDoorCloseTween:Play()
RightDoorCloseTween:Play()
end
end
end)
wait(Cooldown)
print("Waited Cooldown") -- this prints
if IsHiding then -- doesn't run
LeftDoorOpenTween:Play()
RightDoorOpenTween:Play()
HumanoidRootPart.Position = PromptPart.Position
print("Evicted") -- doesn't print
IsHiding = false
Prompt.Enabled = true
wait(TweenTime)
LeftDoorCloseTween:Play()
RightDoorCloseTween:Play()
end
end)
I don’t know why the UIS.InputBegan function is not running, and the two if IsHiding then functions either.
If you need more information, just ask!
Any help is appreciated!
task.wait() isn’t the fix. It will avoid issues in the future, deprecated features should always be avoided.
You seem to have some repeating code. You can clean up your code using a function that will create a coroutine to tween the doors while the rest of your code does it’s work.
local function animateDoors()
coroutine.wrap(function()
LeftDoorOpenTween:Play()
RightDoorOpenTween:Play()
task.wait(TweenTime)
LeftDoorCloseTween:Play()
RightDoorCloseTween:Play()
end)()
end
This code will create a coroutine to animate the doors and immediately run it. If you didn’t use the coroutine, the script would wait for the doors to animate first before continuing.