Reputation: 13
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!
Upvotes: 1
Views: 524
Reputation: 523
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)
Upvotes: 1
Reputation: 56
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.
Upvotes: 0