简体   繁体   中英

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!

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)

If you are trying to detect if a player was joined then Try use this code:

local find = game:GetService("Players")

find.PlayerAdded:Connect(function ()
    print("we found a human")
end)

Copy it into your LocalScript and place your LocalScript in StarterGui library

Learn more about Players here - Learn more about LocalPlayer/Player here

If that's not what you meant to, I will edit the answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM