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

SOMETHING CRAZY IS HAPPENING! Why is everything going infinite yield?

Please help! This is the ENTIRE output;

20:07:16.541 - New Project @ 30 Apr 2017 20:07 was auto-saved
Ragdoll Physics Loaded
Hello world!
20:07:19.599 - Humanoid is not a valid member of Script
20:07:19.600 - Stack Begin
20:07:19.601 - Script 'Plugin_144773946.RealRagdoll.Ragdoll', Line 4
20:07:19.602 - Stack End
Loading Cutscene Editor...
Bouyer's Ragdoll Physics Loaded
Finished Loading.
Loading Tree Gen...
Finished Loading Tree Gen
20:07:20.496 - Unable to load plugin icon. (x2)
Realism Mod is running on v1.795!
Cutscene Editor Loaded
Hello world!
Death
Hello world!
Magnet Punch!
Consuming Powers...
Death
20:07:44.920 - Infinite yield possible on 'Workspace:WaitForChild("Humanoid")'
20:07:44.922 - Stack Begin
20:07:44.924 - Script 'Players.Player1.Backpack.Combat.Main', Line 25
20:07:44.925 - Stack End
20:07:45.389 - Infinite yield possible on 'Workspace:WaitForChild("Humanoid")'
20:07:45.391 - Stack Begin
20:07:45.392 - Script 'Players.Player1.Backpack.Combat.Main', Line 25
20:07:45.394 - Stack End
Hello world!
20:07:47.342 - Infinite yield possible on 'Players.Player1.Backpack:WaitForChild("Right Leg")' (x3)
20:07:47.362 - Infinite yield possible on 'Workspace.Player1.Ultra-Fabulous Hair:WaitForChild("Humanoid")'
20:07:47.609 - Infinite yield possible on 'Workspace.Player1:WaitForChild("Humanoid")' (x4)
20:07:47.657 - Infinite yield possible on 'Workspace:WaitForChild("Humanoid")'
20:07:47.724 - Infinite yield possible on 'Workspace.Player1:WaitForChild("Humanoid")'
20:07:47.775 - Infinite yield possible on 'Workspace:WaitForChild("Humanoid")'
20:08:41.643 - Sent message to server to publish.

This is the script that had a problem;



local Combat = script.Parent
local Animation = game.ReplicatedStorage:WaitForChild("CombatAnimation")
local Fighting = false
local Damage = script.Parent:WaitForChild("Damage")
local StaminaUse = script.Parent:WaitForChild("StaminaUse")
local CurrentStrength = Combat.Parent.Parent:WaitForChild("Status"):WaitForChild("CurrentStrength")
local CurrentStamina = Combat.Parent.Parent:WaitForChild("Status"):WaitForChild("CurrentStamina")
local CurrentStaminaStat = Combat.Parent.Parent:WaitForChild("Status"):WaitForChild("CurrentStaminaStat")
local ToolActivated = false

function onActivation()
	ToolActivated = true
	print("Magnet Punch!")
	local Humanoid = Combat.Parent:WaitForChild("Humanoid")
	local anim = Humanoid:LoadAnimation(Animation)
	anim:Play()
	if Fighting == false then
		Fighting = true
			CurrentStamina.Value = CurrentStamina.Value - StaminaUse.Value
			CurrentStaminaStat.Value = CurrentStaminaStat.Value + StaminaUse.Value
			CurrentStrength.Value = CurrentStrength.Value + StaminaUse.Value
			Combat.Parent:WaitForChild("Right Arm").Touched:connect(function(Hit)
				Hit.Parent:WaitForChild("Humanoid").Health = Hit.Parent:WaitForChild("Humanoid").Health - Damage.Value
				Combat.Parent:WaitForChild("Right Leg").Touched:connect(function(Hit)
					Hit.Parent:WaitForChild("Humanoid").Health = Hit.Parent:WaitForChild("Humanoid").Health - Damage.Value
					wait()
					Fighting = false
					if ToolActivated == false then
					 return
				end
			end)
		end)
	end
end

Combat.Activated:connect(onActivation)

This is the line the where the problem was;

	Hit.Parent:WaitForChild("Humanoid").Health = Hit.Parent:WaitForChild("Humanoid").Health - Damage.Value

But where did All the other Infinite yield came from!? What is happening? Please help!

4 comments

0

I've noticed WaitForChild has done this for me as well. Have you tried FindFirstChild("Humanoid") ?

0

no

0

Alright. I'd like you try using FindFirstChild where you put WaitForChild, and let me know the results!

0

FindFirstChild searches through an object for a specific object once; WaitForChild waits for the object. @iEdwardii

2 answers

✓ Accepted answer

You simply need to make sure that a Humanoid actually exists before waiting for it, so you should use a FindFirstChild check before waiting. Use this updated code that I added the FindFirstChild if statement to.

local Combat = script.Parent
local Animation = game.ReplicatedStorage:WaitForChild("CombatAnimation")
local Fighting = false
local Damage = script.Parent:WaitForChild("Damage")
local StaminaUse = script.Parent:WaitForChild("StaminaUse")
local CurrentStrength = Combat.Parent.Parent:WaitForChild("Status"):WaitForChild("CurrentStrength")
local CurrentStamina = Combat.Parent.Parent:WaitForChild("Status"):WaitForChild("CurrentStamina")
local CurrentStaminaStat = Combat.Parent.Parent:WaitForChild("Status"):WaitForChild("CurrentStaminaStat")
local ToolActivated = false

function onActivation()
    ToolActivated = true
    print("Magnet Punch!")
    local Humanoid = Combat.Parent:WaitForChild("Humanoid")
    local anim = Humanoid:LoadAnimation(Animation)
    anim:Play()
    if Fighting == false then
        Fighting = true
            CurrentStamina.Value = CurrentStamina.Value - StaminaUse.Value
            CurrentStaminaStat.Value = CurrentStaminaStat.Value + StaminaUse.Value
            CurrentStrength.Value = CurrentStrength.Value + StaminaUse.Value
            Combat.Parent:WaitForChild("Right Arm").Touched:connect(function(Hit)
		if Hit.Parent:FindFirstChild("Humanoid") then
             	   Hit.Parent:WaitForChild("Humanoid").Health = Hit.Parent:WaitForChild("Humanoid").Health - Damage.Value
            	    Combat.Parent:WaitForChild("Right Leg").Touched:connect(function(Hit)
                	if Hit.Parent:FindFirstChild("Humanoid") then
                		Hit.Parent:WaitForChild("Humanoid").Health = Hit.Parent:WaitForChild("Humanoid").Health - Damage.Value
           	   		wait()
            	        	Fighting = false
            	      		if ToolActivated == false then
               		      		return
          	        	end
			end
        	    end)
		end
        end)
    end
end

Combat.Activated:connect(onActivation)

5 comments

0

Make sure to upvote and accept if I helped! :)

0

By the way: the reason your script was not working was because the Right Arm and Right Leg were touching things that were not players, causing them to look for a Humanoid in normal parts (non-human objects). If you use WaitForChild on an object that dosen't exist, the script will stop because it will continue to look for said object until it decides to return infinite yield because the object cann

0

ot be found. I hope this helps! :)

0

You don't need to make sure something exists before waiting for it, that defeats the purpose of waiting for it in the first place

0

I will make sure to try!

I'm not fully sure if this script will work, mostly because i wasn't able to test it myself, but here is the script that is maybe fixed.

local Combat = script.Parent
local Animation = game.ReplicatedStorage:WaitForChild("CombatAnimation")
local Fighting = false
local Damage = script.Parent:WaitForChild("Damage")
local StaminaUse = script.Parent:WaitForChild("StaminaUse")
local CurrentStrength = Combat.Parent.Parent:WaitForChild("Status"):WaitForChild("CurrentStrength")
local CurrentStamina = Combat.Parent.Parent:WaitForChild("Status"):WaitForChild("CurrentStamina")
local CurrentStaminaStat = Combat.Parent.Parent:WaitForChild("Status"):WaitForChild("CurrentStaminaStat")
local ToolActivated = false

function onActivation()
    ToolActivated = true
    print("Magnet Punch!")
    local Humanoid = Combat.Parent:WaitForChild("Humanoid")
    local anim = Humanoid:LoadAnimation(Animation)
    anim:Play()
	Fighting = true
	if Fighting == true then return end
		Fighting = true
            CurrentStamina.Value = CurrentStamina.Value - StaminaUse.Value
            CurrentStaminaStat.Value = CurrentStaminaStat.Value + StaminaUse.Value
            CurrentStrength.Value = CurrentStrength.Value + StaminaUse.Value
            Combat.Parent:WaitForChild("Right Arm").Touched:connect(function(Hit)
                Hit.Parent:WaitForChild("Humanoid").Health = Hit.Parent:WaitForChild("Humanoid").Health - Damage.Value
                Combat.Parent:WaitForChild("Right Leg").Touched:connect(function(Hit)
                    Hit.Parent:WaitForChild("Humanoid").Health = Hit.Parent:WaitForChild("Humanoid").Health - Damage.Value
                    wait()
                    Fighting = false
                    if ToolActivated == false then
                     return
                end
            end)
        end)
    end

Combat.Activated:connect(onActivation)

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