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

Why my code is not working? problem--(a nil value) It is one of my first codes.

Asked by
GWA001 0
5 years ago

Hi, I am very new to Roblox and coding I need help with one of my first codes. My code:

script.Parent.Touched:connect(function(hit) local Humanoid = hit.Parent:FindFirstChild("Humaoid") Humanoid.WalkSpeed = 50 end)

I want to make a speed run so I made this code for Padboost but it is not working, it says:
Workspace.Part.Script:3: attempt to index local 'Humanoid' (a nil value) Can you help me, please? Thank you, GWA001

0
Check if the humanoid exists first by using an if statement. Syclya 224 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

Could you format your question better with a code block next time? Thanks. Anyways if the brick is on the ground then the ground can touch it. Here's what you have to do to check if the object touched is the player:

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChildOfClass("Humanoid") then
        -- local Humanoid = hit.Parent:FindFirstChild("Humaoid")
        -- you mispelt Humanoid up there, use FirstChildOfClass instead
        local Humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
        Humanoid.WalkSpeed = 50
    end
end)

Yeah that's it m

0
if you use :FindFirstChildOfClass then if you misspell humanoid it would tell you because it won't be an existing class SindexMon 6 — 5y
Ad

Answer this question