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

What does : attempt to index nil with 'WalkSpeed' mean?

Asked by 4 years ago

this is my script, its supposed to make the enemyhumanoid walkspeed and jumppower 0 but it isnt working

    Hitbox.Touched:Connect(function(Hit)
        if Hit:IsA("Part") or Hit:IsA("MeshPart") then
            if Hit.Parent ~= Character then
                local EHumanoid = Hit.Parent:FindFirstChild("Humanoid")
                local EHumRP = Hit.Parent:FindFirstChild("HumanoidRootPart")

                EHumanoid.WalkSpeed = 16
                EHumanoid.JumpPower = 50

thank you for your time

1
or check (if EHumanoid then) Dfzoz 489 — 4y
0
^ Gey4Jesus69 2705 — 4y
0
^ AntoninFearless 622 — 4y

1 answer

Log in to vote
1
Answered by
4D_X 118
4 years ago

You should see if the Humanoid exists before continuing your code. This can be done with a simple if statement.

Hitbox.Touched:Connect(function(Hit)
    if Hit:IsA("Part") or Hit:IsA("MeshPart") then
        if Hit.Parent ~= Character then
            local EHumanoid = Hit.Parent:FindFirstChild("Humanoid")
            local EHumRP = Hit.Parent:FindFirstChild("HumanoidRootPart")

            if EHumanoid then
                EHumanoid.WalkSpeed = 16
                EHumanoid.JumpPower = 50
            end
        end
    end
end)
Ad

Answer this question