Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why wont my zombie follow script work? line 6?

Asked by 5 years ago
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)

0
Are you sure you aren't using a script? Rare_tendo 3000 — 5y
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 User#23365 30 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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

Ad

Answer this question