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

Why wont my zombie follow script work? line 6?

Zombie = script.Parent
Player = game.Players.LocalPlayer
follow = false

while true do
	if Player.Character.HumanoidRootPart ~= nil then
		if Player.Character.HumanoidRootPart.Position - Zombie.HumanoidRootPart.Position <= 10 then
			follow = true
		end
	end 
	
if follow then
	Zombie.Humanoid.WalkToPoint = Player.Character.HumanoidRootPart
end
	wait(0.5)
end 

i get the error message "Line 6:Attempt to index global "Player" (a nil value)

2 comments

0

Are you sure you aren't using a script?

0

i had this problem, all i just did is put the player variable inside the function or event and it worked, just put the player variable into the while true do loop idk if it will work lol

1 answer

It is nil because the script runs even if the player is not defined. Try this

	Zombie = script.Parent
	Player = game.Players.LocalPlayer
	follow = false
	 
	while true do
	if Player ~= nil then -- checks first if there is player
	    if Player.Character.HumanoidRootPart ~= nil then
	        if Player.Character.HumanoidRootPart.Position - Zombie.HumanoidRootPart.Position <= 10 then
	            follow = true
	        end
	    end
	end
	if follow then
	    Zombie.Humanoid.WalkToPoint = Player.Character.HumanoidRootPart
	end
	    wait(0.5)
	end

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