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)
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.
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.
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)
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)