Tool only works when dropped

I’m pretty new to scripting and I’m making a tool where when equipped, it acts as a security camera and moves the camera to a C-frame of a part. The problem is, I placed it in StarterPack but whenever I test it, it doesn’t work when equipped, it only works when I drop the tool and pick it up again. How would I fix it?

Script:

local Tool = script.Parent
local player = game.Players.LocalPlayer
local char = player.Character
local cam = game.Workspace.CurrentCamera
local Part = script.PartTrag.Value

function onEquippedLocal()
	if cam.CameraType == Enum.CameraType.Custom then
		repeat wait()
			cam.CameraType = Enum.CameraType.Scriptable
		until cam.CameraType == Enum.CameraType.Scriptable
		cam.CFrame = Part.CFrame
		cam.FieldOfView = 40
	end
end


function onUneqippedLocal()
	cam.CameraType = Enum.CameraType.Custom
	cam.FieldOfView = 70
end


Tool.Equipped:connect(onEquippedLocal)
Tool.Unequipped:connect(onUneqippedLocal)

Is there any errors that show up?

On the output it says, 16:59:10.137 PartTrag is not a valid member of LocalScript “Players.Sean_lbgl.Backpack.View Stage.LocalScript” - Client - LocalScript:5

It says that PartTrag isn’t a children of the local script.

PartTrag exists as a child of the tool’s script?

I am confused by what this instance is. Is it a value or a BasePart?

Capture

It’s a child of the LocalScript in the tool

Try to use WaitForChild() on the PartTrag instance instead of just indexing it.

1 Like