The function <Object>:WaitForChild(<thing>,<timeout>) as you can see it has two arguments One for the name of the object you're looking for and a timeout (in seconds). So if you have no timeout in your script's it will hang for a while until the timeout error Infinite yield is thrown.
The proper way to use the function is as follows:
--Wrong way (kinda)
local rarm = script.Parent:WaitForChild("Right Arm")
local larm = script.Parent:WaitForChild("Left Arm")
function dmg(hit)
if hit.Parent ~= nil then
local hum = hit.Parent:findFirstChild("Humanoid")
if hum ~= nil then
hum.Health = hum.Health -10
end
end
end
rarm.Touched:connect(dmg)
larm.Touched:connect(dmg)
Correct Way:
local rarm = script.Parent:WaitForChild("Right Arm",10)
local larm = script.Parent:WaitForChild("Left Arm",10)
function dmg(hit)
if hit.Parent ~= nil then
local hum = hit.Parent:findFirstChild("Humanoid")
if hum ~= nil then
hum.Health = hum.Health -10
end
end
end
local ChkTable = {rarm,larm}
if(#ChkTable < 2) then
if(rarm == nil) then warn("Error: Right Arm is nil!") end
if(larm == nil) then warn("Error: Left Arm is nil!") end
error("Error: Something went wrong with WaitForChild() Checks as not all objects are found in the check table!")
end
rarm.Touched:connect(dmg)
larm.Touched:connect(dmg)
ask if your unsure on anything and Hope this helps! :)
1 comment
I don't see zombieradio anywhere