Search code examples
luaroblox

wait for child not working (roblox studio)


local find = script.Parent    
find.Touched:Connect(function(touched)
local de = find:FindFirstChild("Humanoid")
if de == true then
    print("we found a human!")

end

end)

is not working?? I'm new to this but i just don't understand!


Solution

  • The reason why your script is not functioning as intended is because :FindFirstChild() will return an object. (not a boolean)

    So your statement is practically stating

    local part = Instance.new("Part")
    if part == true then -- Part does not equal true
    

    The solution is quite simple. When :FindFirstChild() doesn't find anything it will return nil. So just make sure that it `~=~ nil

    local find = script.Parent    
    find.Touched:Connect(function(touched)
        local de = touched.Parent:FindFirstChild("Humanoid")
        if de ~= nil then -- checking if a humanoid was found
            print("we found a human!")
        end
    end)