Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

camera doesn't reset after death ?

Asked by 2 years ago
Edited 2 years ago

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

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

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.

0
it hasn't worked i put it before the true loop and it just zoomed in jackthetroll2411 5 — 2y
0
figured out what the problem was and updated the answer with the updated code sergeant_ranger 184 — 2y
Ad

Answer this question