Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago

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)
0
this script is inside the handle of a sword. MPforfun 91 — 5y
0
is this script even related to the error SuperSamyGamer 316 — 5y
0
Which isn't an error, it just means that the rest of the script might not carry on until that "WaitForChild" finishes SuperSamyGamer 316 — 5y
0
Use GetPlayerFromCharacter(). DeceptiveCaster 3761 — 5y
View all comments (2 more)
0
Also, infinite yield is not an error. It's a warning. DeceptiveCaster 3761 — 5y
0
I think you posted the wrong script. Y_VRN 246 — 5y

1 answer

Log in to vote
1
Answered by
ClouZek 16
4 years ago
Edited 4 years ago
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

Ad

Answer this question