Hi there. I've been messing around with making a custom dead, and I want to make the cameratype "Scriptable" (So that it doesn't move) and make it "custom" back again when you respawn and make the camerasubject the humanoid back. I tried lots of codes,like this one, which is the actual one, but it simply freezes studio and forces an exit.
local Players = game:GetService("Players") local Playername = game.Players.LocalPlayer local plr = game.Players.LocalPlayer local hum = game:GetService("Players").LocalPlayer.Character script.Parent.Humanoid.Died:connect(function() game.Workspace.Camera.CameraType = "Scriptable" end) while true do local chr = plr.Character or plr.CharacterAdded:wait() game.Workspace.Camera.CameraType = "Custom" game.Workspace.Camera.CameraSubject = hum.Humanoid end
I'm starting to think in suicide. Just help please!
You would be better off adding a local script into StarterCharacterScripts to do this task. Since it needs to be ran when the player spawns though there is nothing stopping you from using a alternative method but you will need to include additional events for the player spawning ect.
The issue is that you have an infinite loop.
while true do -- this will make the script wait but after the payer is found cause an inf loop with no yield (wait) local chr = plr.Character or plr.CharacterAdded:wait() game.Workspace.Camera.CameraType = "Custom" game.Workspace.Camera.CameraSubject = hum.Humanoid end
Always use events over loops.
something like this should work well
local camera = workspace.CurrentCamera local humanoid = script.Parent:WaitForChild('Humanoid') camera.CameraType = Enum.CameraType.Custom camera.CameraSubject = humanoid humanoid.Died:Wait() -- wait for the player to die camera.CameraType = Enum.CameraType.Scriptable
I hope this helps.