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

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

Asked by 7 years ago

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!

0
I've noticed WaitForChild has done this for me as well. Have you tried FindFirstChild("Humanoid") ? iEdwardii 22 — 7y
0
no BlackOrange3343 2676 — 7y
0
Alright. I'd like you try using FindFirstChild where you put WaitForChild, and let me know the results! iEdwardii 22 — 7y
0
FindFirstChild searches through an object for a specific object once; WaitForChild waits for the object. @iEdwardii TheeDeathCaster 2368 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago

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)
0
Make sure to upvote and accept if I helped! :) joritochip 705 — 7y
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 joritochip 705 — 7y
0
ot be found. I hope this helps! :) joritochip 705 — 7y
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 Pyrondon 2089 — 7y
0
I will make sure to try! BlackOrange3343 2676 — 7y
Ad
Log in to vote
0
Answered by
wookey12 174
7 years ago

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)

Answer this question