I’m trying to make a script that forces the CurrentCamera to lock to the character’s head on death but it just sets the CFrame once. Here is the video:
repeat wait () until game:IsLoaded()
local camera = workspace.CurrentCamera
local function reset()
repeat camera.CameraType = Enum.CameraType.Fixed until camera.CameraType == Enum.CameraType.Fixed
end
script.Parent:WaitForChild("Humanoid").Died:Connect(function()
camera.CameraType = Enum.CameraType.Scriptable
repeat
camera.CFrame = script.Parent:FindFirstChild("Head").CFrame
wait(0.01)
print("repeat")
until game.Players.LocalPlayer.CharacterAdded
end)
game.Players.LocalPlayer.CharacterAdded:Connect(function()
reset()
print("reset")
end)
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local head = character:WaitForChild("Head")
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Fixed
local function onHumanoidDied()
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = head.CFrame
end
humanoid.Died:Connect(onHumanoidDied)
Local script inside StarterCharacterScripts, you may wish to swap the camera type when spawning from fixed to track (so the camera follows the player’s character).
the problem with your script is that game.Players.LocalPlayer.CharacterAdded will always be true because its an event
its like the script is repeating until the event exists
here’s my idea to fix it:
script.Parent:WaitForChild("Humanoid").Died:Connect(function()
camera.CameraType = Enum.CameraType.Scriptable
repeat
camera.CFrame = script.Parent:FindFirstChild("Head").CFrame
task.wait() --use task.wait cuz its more precise and syncs to heartbeat (optional)
print("repeat")
until game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character.Humanoid.Health > 0 --checks if player has a character, and if it does, checks if players character is alive
end)
Probably because you were setting the camera type to fixed (which locks the camera in place, in this case each time the player’s character spawns), I did suggest in my notes provided that you should set the camera type to track instead (as this is the default mode).