So, I’ve been making a difficulty chart obby, and the first thing I wanted to do is to play a cutscene when you first join. But I’ve ran up into an issue in my script in which the look loop doesn’t work.
Here is the script I made.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage:WaitForChild("Events")
Events.PlayCutscene.OnClientEvent:Connect(function()
local IntroAnimation = game.Players.LocalPlayer.Character.Humanoid.Animator:LoadAnimation(script.Intro) :: AnimationTrack
IntroAnimation:Play(0)
IntroAnimation:GetMarkerReachedSignal("StartCameraLook"):Connect(function()
print("start")
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
repeat
workspace.CurrentCamera.CFrame = CFrame.lookAt(workspace.CurrentCamera.CFrame.Position, game.Players.LocalPlayer.Character.PrimaryPart.Position)
task.wait()
until IntroAnimation:GetMarkerReachedSignal("StopCameraLook")
print("stop")
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
end)
end)
1 Like
Try this instead
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Events = ReplicatedStorage:WaitForChild("Events")
local updateCameraEvent = nil
Events.PlayCutscene.OnClientEvent:Connect(function()
local IntroAnimation = game.Players.LocalPlayer.Character.Humanoid.Animator:LoadAnimation(script.Intro) :: AnimationTrack
IntroAnimation:GetMarkerReachedSignal("StartCameraLook"):Connect(function()
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
if updateCameraEvent then return end
updateCameraEvent = RunService.Heartbeat:Connect(function()
workspace.CurrentCamera.CFrame = CFrame.lookAt(workspace.CurrentCamera.CFrame.Position, game.Players.LocalPlayer.Character.PrimaryPart.Position)
end)
end)
IntroAnimation:GetMarkerReachedSignal("StopCameraLook"):Connect(function()
if updateCameraEvent then
updateCameraEvent:Disconnect()
updateCameraEvent = nil
end
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
end)
IntroAnimation:Play(0)
end)
1 Like
This worked as nicely as it could. Thank you!