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

Make camera locks when dead?

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!

1 comment

0

Try and attach the camera to the torso.

1 answer

✓ Accepted answer

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.

1 comment

0

Thanks! I'll mess up again my code with your tip. i'm a newbie and I didn't had idea about wait in loops xd

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