Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to fix error Infinite yield possible on 'Workspace.:WaitForChild("Humanoid")?

i have a sword script and it will stop working and this will show up in the output 21:40:31.563 - Infinite yield possible on 'Workspace.:WaitForChild("Humanoid")' im not sure how to fix it but here is the script

local Obj = script.Parent

local Debounce = true

Obj.Touched:connect(function(Hit)
	if Debounce == true then
		Debounce = false
			wait()
			if Hit.Parent:findFirstChild("Humanoid") then
				Hit.Parent.Humanoid:TakeDamage(15)
				wait(1)
				Debounce = true
		end
	end
end)

6 comments

0

this script is inside the handle of a sword.

0

is this script even related to the error

0

Which isn't an error, it just means that the rest of the script might not carry on until that "WaitForChild" finishes

0

Use GetPlayerFromCharacter().

0

Also, infinite yield is not an error. It's a warning.

0

I think you posted the wrong script.

1 answer

✓ Accepted answer
1
local Obj = script.Parent
02
 
03
local Debounce = true
04
 
05
Obj.Touched:connect(function(Hit)
06
    if Debounce == true then
07
        Debounce = false
08
            wait()
09
            if Hit.Parent:FindFirstChild("Humanoid") then
10
                Hit.Parent.Humanoid.Health = Hit.Parent.Humanoid.Health -15
11
                wait(1)
12
                Debounce = true
13
        end
14
    end
15
end)

remove numbers

This discussion is preserved as it was. New answers, comments, and votes are closed.