I’m trying to simulate a bird’s eye-view camera on my game, but the problem is that when the character dies (e.g. when the player resets it), the camera locks on the last character’s position before he died and when he respawns, it stays there, not moving at all.
Here’s the script I’m using, located in StarterPlayerScripts:
local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local root = character:WaitForChild('HumanoidRootPart')
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
RunService.RenderStepped:Connect(function()
if not root then return end
camera.CFrame = CFrame.new(root.CFrame.X , root.CFrame.Y + 30, root.CFrame.Z + 5) * CFrame.Angles(math.rad(-80), 0, 0)
end)
When you declare local root = character:WaitForChild('HumanoidRootPart') , Lua stores a reference to the root part once and never checks for a new one; your variable root only pertains to the first spawning of the character’s root. A really simple way to fix this is by placing your script in StarterCharacterScripts so that it refreshes upon respawn automatically.
Quick edit: If you do this, you can simply reference the character through the script’s parent since the script is replicated within the character model for every spawn.