Can't find Humanoid

Hi, I have a script that doesn’t find the humanoid when it should. So this Part (that has this script) gets cloned and when it does, it waits for a remote event to be fired. once its fired, it checks if someone is touching the part. but when it looks for the humanoid, it says Infinite yield possible on ‘Workspace.Model:WaitForChild(“Humanoid”)’. How do i fix this? this is my script below:

local hitbox = script.Parent
local players = game:GetService("Players")
local callrotate = game.ReplicatedStorage.Remotes.CallRotate
local lbremote = game.ReplicatedStorage.Remotes.Lightsaber
local getplayerbh = game.ReplicatedStorage.Remotes.Getplayeybh
local debounce = false
local whosimmune = script.Parent.Parent.Immune
getplayerbh.OnServerEvent:Connect(function(player)
	print("fired hitbox")
	local touching = game.Workspace:GetPartsInPart(hitbox)
	for i, v in pairs(touching) do
		local humanoid = v.Parent:WaitForChild("Humanoid")
			lbremote:FireClient(player)
			whosimmune.Name = player.Name
			local clonekillscript = game.ServerStorage.DebuffScripts.KillLB:Clone()
			if v.Parent:FindFirstChild("KillLB") == nil then
				if humanoid.Health > 0 then
					clonekillscript.Parent = humanoid.Parent
				end


			else
				if humanoid.Health > 0 then
					v.Parent.KillLB:Destroy()
					clonekillscript.Parent = humanoid.Parent
				end


			end
			if v.Parent:FindFirstChild("Humanoid") ~= nil and not v.Parent:FindFirstChild("BlackHoleRotate") and v.Parent.Name ~= whosimmune.Name then
				print("is touching")
				local blackholescript = game.ReplicatedStorage.Scripts.BlackHoleRotate:Clone()
				blackholescript.Parent = v.Parent
				callrotate:FireClient(game.Players:GetPlayerFromCharacter(v.Parent))










				v.Parent.Humanoid.Health -= 5
				task.wait(1)
				v.Parent.Humanoid.Health -= 5
				task.wait(1)
				v.Parent.Humanoid.Health -= 5
				task.wait(1)
				v.Parent.Humanoid.Health -= 5

			end
		end

	end)

try this

local hitbox = script.Parent
local players = game:GetService("Players")
local callrotate = game.ReplicatedStorage.Remotes.CallRotate
local lbremote = game.ReplicatedStorage.Remotes.Lightsaber
local getplayerbh = game.ReplicatedStorage.Remotes.Getplayeybh
local debounce = false
local whosimmune = script.Parent.Parent.Immune

getplayerbh.OnServerEvent:Connect(function(player)
    print("fired hitbox")
    local touching = game.Workspace:GetPartsInPart(hitbox)
    
    for i, v in pairs(touching) do
        if v.Parent then
            if v.Parent:FindFirstChild("Humanoid") then
                local humanoid = v.Parent:FindFirstChild("Humanoid")
                lbremote:FireClient(player)
                whosimmune.Name = player.Name
                local clonekillscript = game.ServerStorage.DebuffScripts.KillLB:Clone()

                if v.Parent:FindFirstChild("KillLB") == nil then
                    if humanoid.Health > 0 then
                        clonekillscript.Parent = humanoid.Parent
                    end
                else
                    if humanoid.Health > 0 then
                        v.Parent.KillLB:Destroy()
                        clonekillscript.Parent = humanoid.Parent
                    end
                end

                if v.Parent:FindFirstChild("Humanoid") and not v.Parent:FindFirstChild("BlackHoleRotate") and v.Parent.Name ~= whosimmune.Name then
                    print("is touching")
                    local blackholescript = game.ReplicatedStorage.Scripts.BlackHoleRotate:Clone()
                    blackholescript.Parent = v.Parent
                    callrotate:FireClient(game.Players:GetPlayerFromCharacter(v.Parent))

                    for _ = 1, 4 do
                        v.Parent.Humanoid.Health -= 5
                        task.wait(1)
                    end
                end
            end
        end
    end
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.