Why does this index nil with character?

image

local part = script.Parent
local player = game.Players.LocalPlayer 
local speed = 5  

local function followPlayer()
	local character = player.Character
	if character then
		local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
		local direction = (humanoidRootPart.Position - part.Position).unit
		part.CFrame = part.CFrame:Lerp(CFrame.new(part.Position, humanoidRootPart.Position), 0.1 * speed)
	end
end

while true do
	followPlayer()
	wait(0.1)
end

1 Like

This is a ServerScript or LocalScript?

1 Like

You cannot use game.Players.LocalPlayer on a server script.

Do not fix this using a local script inside of the part, as local scripts do not run outside of the player.

2 Likes

i was so confused turns out i just accidently put it in a severscript

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.