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

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

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

1 comment

0

Check if the humanoid exists first by using an if statement.

1 answer

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

1 comment

0

if you use :FindFirstChildOfClass then if you misspell humanoid it would tell you because it won't be an existing class

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