The death cam script is working fine, well at least on the first death. When the player respawns, the camera returns back to the original but the death cam script won’t work again. It just only works on one death. Here is my code:
wait(0.1)
local Humanoid = script.Parent.Parent.Character:WaitForChild("Humanoid")
local RS = game:GetService("RunService")
local Cons = {}
Humanoid.Died:Connect(function()
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
for _, conneys in Cons do
conneys:Connect()
end
table.insert(Cons, RS.RenderStepped:Connect(function()
local TorsoPos = Humanoid.Parent.Torso.Position
local CurCamPos = workspace.CurrentCamera.CFrame.Position
workspace.CurrentCamera.CFrame = CFrame.lookAt(CurCamPos, TorsoPos)
end))
end)
game.Players.LocalPlayer.CharacterAdded:Connect(function()
for _, conneys in Cons do
conneys:Disconnect()
end
table.clear(Cons)
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
end)
I’m may be wrong, but I think the humanoid can only die once because the character model gets deleted and replaced. The humanoid variable, that you connect the function too, will get disconnected when the character is replaced. You’ll need to declare the variable and connect the function as local inside the character added function. Hope this makes sense.
I tried putting the humanoid variable in function covered by table.insert and it still didn’t work. I even correct the Humanoid.Died with script.Parent.Parent.Character.Humanoid and it still didn’t work. Left no errors either.
Where is this local script located? Inside the character model or the player scripts folder?
If its inside PlayerScripts try this:
game.Players.LocalPlayer.CharacterAdded:Connect(function()
local newlyAddedHumanoid = game.Players.LocalPlayer.Character
for _, conneys in Cons do
conneys:Disconnect()
end
table.clear(Cons)
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
local connection = Humanoid.Died:Connect(function()
connection:Disconnect()
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
for _, conneys in Cons do
conneys:Connect()
end
table.insert(Cons, RS.RenderStepped:Connect(function()
local TorsoPos = Humanoid.Parent.Torso.Position
local CurCamPos = workspace.CurrentCamera.CFrame.Position
workspace.CurrentCamera.CFrame = CFrame.lookAt(CurCamPos, TorsoPos)
end))
end)
end)
I fixed it, all I had to do was set the camera subject and put the disconnect lines of code at the start of the script. Big huge props to anyone that commented on this post and tried to help me.