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

2D Camera System stops following when character respawns second time?

Asked by
cactz 15
3 years ago
Edited 3 years ago

This happens if I my character respawns second time

local player = game:GetService("Players").LocalPlayer
local camera = workspace.CurrentCamera or workspace.Camera
local follow = true
local con
local RootPart 

player.CharacterAdded:wait()
player.Character:waitForChild'HumanoidRootPart'
local hum = player.Character:waitForChild'Humanoid'

con = hum.Died:Connect(function()
    hum = nil
    follow = false
    con:Disconnect()
    con = nil
end)
RootPart = player.Character:waitForChild'HumanoidRootPart'
camera.CameraSubject = RootPart
camera.CameraType = Enum.CameraType.Scriptable
camera.FieldOfView = 70

function refresh()
if con then
    con:Disconnect()
    con = nil 
end
follow = true

player.CharacterAdded:wait()
player.Character:waitForChild'HumanoidRootPart'
hum = player.Character:waitForChild'Humanoid'

con = hum.Died:Connect(function()
    hum = nil
    follow = false
    con:Disconnect()
    con = nil
end)
RootPart = player.Character:waitForChild'HumanoidRootPart'
camera.CameraSubject = RootPart
camera.CameraType = Enum.CameraType.Scriptable
camera.FieldOfView = 70

end
player.CharacterAdded:connect(refresh)

game:GetService("RunService").Heartbeat:Connect(function()
    if follow then
        camera.CFrame = CFrame.new(RootPart.Position) * CFrame.new(0,2,15)
    end
end)
0
Where is the script located ? VerdommeMan 1479 — 3y
0
StarterPlayerScripts and named "CameraScript" cactz 15 — 3y

Answer this question