Help with Humanoid Walkspeed and :destroy()

Hello I am a beginner scripter and Game developer, and I need help with this code

local part = script.Parent

part.Touched:Connect(function(touched)
	local humanoid = touched.Parent:WaitForChild("Humanoid")
	if humanoid then
		if humanoid.WalkSpeed >= 32 then
			part:Destroy()
		end
	end
end)

(Sorry if this is an armature-ish question, I am a self taught scripter and this is my first post)

Thank you in advanced :)))

1 Like

I forgot to mention that this script is in a part

If a part that doesn’t have a humanoid touches your part, it’s going to yield forever. Use :FindFirstChild() to check if the part that touched it does have a humanoid first.

2 Likes

What’s your problem/goal? From what I see, you are checking if the player has a walkspeed of 32 or more. If the player that touched the part does have that specified walkspeed, then the part will destroy.

1 Like

In my game the player can sprint and the speed will gradually increase, I’m trying to make a crate that players can destroy at certain speed

Maybe try @NotMonkeyBusiness’s solution?

1 Like

Is this what you mean? if that is so it doesn’t seem to work

local part = script.Parent

part.Touched:Connect(function(touched)
	if 	touched:FindFirstChild("Humanoid") then
		local humanoid = touched.Parent:WaitForChild("Humanoid")
		if humanoid.WalkSpeed >= 32 then
			part:Destroy()
		end
	end
end)

(sorry if this is wrong, as I said I am a beginner)

touched.Parent:FindFirstChild()

local part = script.Parent

part.Touched:Connect(function(touched)
local humanoid = touched.Parent:FindFirstChild("Humanoid")
		if humanoid and humanoid.WalkSpeed >= 32 then
			part:Destroy()
		end
	end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.