Object value attempt to index nil with FindFirstChild

i want to character follow the player that was set in object value but when im writing local with object value it just says "attempt to index nil with FindFirstChild "

local NPC = script.Parent
while true do
	local player = script.Parent.Parent.Creator.Value
	NPC.Humanoid:MoveTo(player:FindFirstChild("HumanoidRootPart").Position)
	local stopped 
	NPC.Humanoid.MoveToFinished:Connect(function()
		stopped = true
	end)
	repeat 
		local distance = (NPC:WaitForChild("HumanoidRootPart").Position-player:FindFirstChild("HumanoidRootPart").Position).Magnitude
		if distance < 10 then
			NPC.Humanoid:MoveTo((NPC.HumanoidRootPart.CFrame*CFrame.new(5,0,0)).p)
			break
		end
		wait()
	until stopped == true
	wait(0.5)
end


Help me i dont know whats wrong with it

1 Like

If the value is nil just return, can’t help further without seeing the script that sets the ObjectValue’s value.

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild ("Humanoid") then
	    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if db == true then
			db = false
			local BTTCharacters = game:GetService("ReplicatedStorage").BTTCharacters:Clone()
			BTTCharacters.Parent = player.Character
			BTTCharacters.Creator.Value = player.Character
			task.wait(0.5)
			BTTCharacters:PivotTo(player.Character:WaitForChild("HumanoidRootPart").CFrame)
			wait(1)
			db = true
		end
	end
end)

that’s the script that sets object value

it would be cool if you answser me, if you dont know how to do this then ok

why you dont place directly the HumanoidRootPart at the object value?

hmmm… that can work, let me test it

I gave you a possible answer approximately 202,980 seconds ago. Also don’t even bother trying to press out an answer with that cheesy ahh sentence, it’s just pathetic.