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

Make camera locks when dead?

Asked by
Aimarekin 345 Moderation Voter
6 years ago
Edited 6 years ago

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!

0
Try and attach the camera to the torso. nap516 87 — 6y

1 answer

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

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.

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 Aimarekin 345 — 6y
Ad

Answer this question