So I’m making an Endless Runner. When the player goes to a portal. The Camera changes so it’s like a 2D Endless Runner game, and I want it so that when the character dies. It changes the Camera to focus on the player, but problem is. When it does happen. It will print died but it just keeps the camera at one spot
Here is the Script :
repeat wait()
until game:IsLoaded()
local wait0 = require(script:WaitForChild("WaitModule"))
local cam = script.GameCam
local camera = workspace.CurrentCamera
local char = script.Parent
local HRP = char:WaitForChild("HumanoidRootPart")
local RS = game:GetService("RunService")
local function weld()
local weld = Instance.new("WeldConstraint")
weld.Part0 = HRP
cam.Position = Vector3.new(HRP.Position.X,HRP.Position.Y,-40)
cam.Parent = workspace
weld.Part1 = cam
weld.Parent = HRP
RS.RenderStepped:Connect(function()
cam.Position = Vector3.new(HRP.Position.X,HRP.Position.Y,-40)
weld.Part1 = cam
end)
RS.RenderStepped:Connect(function()
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.lookAt(cam.Position,HRP.Position)
camera.Focus = HRP.CFrame
end)
end
workspace.Lobby.EndlessPortal.gate.Touched:Connect(weld)
spawn(function()
while true do
wait0(1)
if char.Humanoid.Health == 0 then
wait0()
print("Died")
camera.CameraSubject = char:WaitForChild("Humanoid")
camera.CFrame = char.HumanoidRootPart.CFrame
camera.Focus = char.HumanoidRootPart.CFrame
camera.CameraType = Enum.CameraType.Track
workspace.Lobby.EndlessPortal.gate.Touched:Connect(weld)
end
end
end)