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

attempt to index nil with 'Position'?

Asked by 3 years ago

So what I was trying to do here was make the enemy follow the player and the error, " Workspace.Enemy.Humanoid.Walk:6: attempt to index nil with 'Position'" popped up, anyone have answers?

local enmhum = script.Parent.Parent.Humanoid
local nearestHumanoid = findNearestHumanoid
local map
if nearestHumanoid then
    map = nearestHumanoid.Position
end

while wait() do
    for i,v in pairs(game.Players:GetChildren())do
        local character = game.Workspace:WaitForChild(v.Name)
        enmhum:MoveTo(character.PrimaryPart.Position)

        script.Parent.Touched:Connect(function(hit)
            if hit.Parent.Name == character.Name then
                character.Humanoid.Health = character.Humanoid.Health == 50
                if hit.Parent.Name == character.Name then
                    character.Humanoid.Health = character.Humanoid.Health == 1
                end
            end
        end)
    end
end

Thank you!

1
what is the nearesthumanoid supposed to do? On line 02. ShineBright2775 30 — 3y
0
If it's a function that returns you the humanoid. You forgot the (). And humanoid doesn't have a position, instead, get the humanoid root part from the humanoid parent. LightningLIon58 49 — 3y

Answer this question