I am making a door trasition cutscene type thing and when the players walks through the door it teleports them to a location, but it does it twice as shown in this video.
Also here is my code for it.
local DoorHandler = {}
local CameraHandler = require(script:WaitForChild("CameraHandler"))
local isTeleported = false
local hasWalked = false
function DoorHandler.setupDoorAnimation(doorModel, teleportDestination, animationTime, Trigger, Hinge, camPart)
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer -- Assign 'player' here
local function teleportPlayer()
local HRP = player.Character:FindFirstChild("HumanoidRootPart")
HRP.CFrame = CFrame.new(teleportDestination.Position)
end
local originalCFrame = Hinge.CFrame
local targetOpen = originalCFrame * CFrame.Angles(0, math.rad(90), 0)
local targetClose = originalCFrame * CFrame.Angles(0, 0, 0)
local function disablePlayerControls()
local PlayerControl = require(game:GetService("Players").LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerControl:GetControls()
Controls:Disable()
end
local function enablePlayerControls()
local PlayerControl = require(game:GetService("Players").LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerControl:GetControls()
Controls:Enable()
end
local function makePlayerWalk()
local character = player.Character or player.CharacterAdded:Wait()
local walkDirection = Vector3.new(1, 0, 0)
local humanoid = character:FindFirstChildOfClass("Humanoid")
if hasWalked == false then
humanoid:Move(walkDirection)
end
end
local function openDoorAnimation()
local character = player.Character or player.CharacterAdded:Wait()
local camera = game.Workspace.Camera
local tweenInfoCamera = TweenInfo.new(animationTime, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local tweenCamera = TweenService:Create(camera, tweenInfoCamera, { CFrame = camPart.CFrame })
local tweenInfo = TweenInfo.new(animationTime, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local tweenCloseInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local tweenOpen = TweenService:Create(Hinge, tweenInfo, { CFrame = targetOpen })
local tweenClose = TweenService:Create(Hinge, tweenCloseInfo, { CFrame = targetClose })
camera.CameraType = Enum.CameraType.Scriptable
tweenOpen:Play()
tweenCamera:Play()
tweenOpen.Completed:Wait()
disablePlayerControls()
isTeleported = false
makePlayerWalk()
wait(0.7)
tweenClose:Play()
hasWalked = true
teleportPlayer()
isTeleported = true
enablePlayerControls()
if isTeleported == true then
CameraHandler.lockCamera()
workspace.Camera.CameraType = Enum.CameraType.Custom
end
end
Trigger.Touched:Connect(function(otherPart)
local character = otherPart.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
local debounce = false
if humanoid and humanoid:IsA("Humanoid") and character:IsA("Model") and character:FindFirstChild("Humanoid") and debounce == false then
debounce = true
openDoorAnimation()
wait(4)
debounce = false
end
end)
end
return DoorHandler
Any help with be very much appreciated!