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

CameraOffset Script Doesn't Work After I Respawn, How Do I Fix This?

So I found this script that makes the camera focus on the player's head, but whenever i die and respawn it just doesn't work anymore. Can someone tell me what the problem is and how to fix it? here's the code;

local plr = game.Players.LocalPlayer
local char = plr.CharacterAdded:wait()
local hum = char:WaitForChild("Humanoid")
local rootpart,head = char:WaitForChild("HumanoidRootPart"),char:WaitForChild("Head")
game:GetService("RunService"):BindToRenderStep("CameraOffset",Enum.RenderPriority.Camera.Value-1,function()
	hum.CameraOffset = (rootpart.CFrame+Vector3.new(0,1.5,0)):pointToObjectSpace(head.CFrame.p)
end)

Other info: This is a LocalScript located in StarterPlayerScripts, and FilteringEnabled is on

also i only know the pure basics of scripting so please don't confuse me :p

1 comment

0

Could you please accept the answer if it worked?

1 answer

✓ Accepted answer

It stops working after you respawn because it is in PlayerScripts. A new instance of the PlayerScripts folder is not created when you respawn. Only new instances of Backpack, PlayerGui, and the player's Character are created when you respawn. If you move this to StarterCharacterScripts, and change

local char = plr.CharacterAdded:wait()

to

local char = script.Parent

it will work.

1 comment

0

alright thanks

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