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

How do you fix a script when you reset your character?

If you do not understand the title then what i mean is that when you character dies my script is broken.

Please help

local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
repeat wait() until player.Character
local rootpart = player.Character.HumanoidRootPart

camera.CameraType = Enum.CameraType.Scriptable
camera.CameraSubject = rootpart

game:GetService("RunService").RenderStepped:connect(function()
	camera.CFrame = CFrame.new(rootpart.CFrame.X, rootpart.CFrame.Y, rootpart.CFrame.Z + 15)	
end)

1 comment

0

Use the code block, it has the Lua label

1 answer

✓ Accepted answer
local camera = workspace.CurrentCamera
local plrService = game:GetService("Players")
local lPlr = plrService.LocalPlayer
local runService = game:GetService("RunService")

local rootPart

camera.CameraType = Enum.CameraType.Scriptable

local function doCamera()
	if lPlr.Character and rootPart then
		camera.CFrame = CFrame.new(rootPart.CFrame.p)
	end
end

runService.RenderStepped:Connect(doCamera)

lPlr.CharacterAdded:Connect(function(char)
	rootPart = char:WaitForChild("HumanoidRootPart")
	camera.CameraSubject = rootPart
end)

1 comment

0

Thanks a lot!

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