Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

camera doesn't reset after death ?

So my camera script works completely fine untill i die, the camera stays in the same place and doesnt move eg


local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
repeat wait() until plr.Character
local char = plr.Character
local cam = game.Workspace.CurrentCamera
local zoom = 100
cam.FieldOfView = 15
cam.CameraType = Enum.CameraType.Scriptable
mouse.WheelForward:connect(function()
    if zoom > 70 then
        zoom = zoom - 2
    else
        zoom = 80
    end
end)
mouse.WheelBackward:connect(function()
    if zoom < 100 then
        zoom = zoom + 2
    else
        zoom = 100
    end
end)
while true do
    game["Run Service"].RenderStepped:wait()
    if char then
        if char:FindFirstChild("Head") then
            cam.CoordinateFrame = CFrame.new(Vector3.new(char.Head.Position.X+zoom,char.Head.Position.Y+zoom,char.Head.Position.Z+zoom),char.Head.Position)
        end
    end
end

1 answer

It looks like the problem is probably the script continues to refer to a camera and character that has changed. On death, the camera and character are deleted and respawned, but the variables dont look like they reflect that change. So all you should need to do is add:

plr.CharacterAdded:Connect(function()
	repeat wait() until plr.Character
	char = plr.Character
	cam = workspace.CurrentCamera
end)

before the while true do loop.

2 comments

0

it hasn't worked i put it before the true loop and it just zoomed in

0

figured out what the problem was and updated the answer with the updated code

This discussion is preserved as it was. New answers, comments, and votes are closed.