Infinite Yield on HumanoidRootPart

Well, the title is self explanatory, I’ve made a slide script for my parkour game and It worked quite fine, didn’t give any error, but yesterday, the script started giving problems. I don’t really know why, I didn’t change anything on the script (I think) so I couldn’t realize why It started outputing infinite yields possible.

I’ve made some tweaks to the code that should break the infinite yield, but it’s still not working. Im 99% sure that the script is giving the problems, because I tried disabling all the scripts but I still can’t find the solution.

LocalScript's code
wait(1)

----------------
-- Services
----------------

local UserInput = game:GetService("UserInputService")
local ContextAction = game:GetService("ContextActionService")

----------------
-- Character
----------------

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded():Wait() or script.Parent.Parent
local hum = char:WaitForChild("Humanoid") or char.Humanoid
local hrp = char:WaitForChild("HumanoidRootPart") or char.HumanoidRootPart

print(char.Name)
print(hum.Name)
print(hrp.Name)

local doubleJumpDisabler = char:WaitForChild("Movement"):WaitForChild("doubleJump")

--// animations
local slide = game.ReplicatedStorage.slide:Clone()
slide.Parent = char
local slideAnim = hum:LoadAnimation(slide)

----------------
-- Values
----------------

local debounce = false
local oldPower
local oldAngle

-- Functions

local function slideRequest()
	if (not debounce and hrp.Velocity.Magnitude > .5) then
		
		if (hrp) then
			hrp.CustomPhysicalProperties = PhysicalProperties.new(.7, 0.2, 0, 1, 0) --// Preventing nearly infinite sliding
		end
		
		debounce = true
		oldPower = hum.JumpPower
		oldAngle = hum.MaxSlopeAngle
		
		hum.JumpPower = 0
		hum.MaxSlopeAngle = 15
		
		slideAnim:Play()
		
		doubleJumpDisabler.Disabled = true
	end
end

local function stopSlide(trigger)
	
	if (hrp) then
		hrp.CustomPhysicalProperties = PhysicalProperties.new(1.1, 0.2, 0, 1, 0) --// Setting back physical properties
	end
	
	slideAnim:Stop()
	hum.JumpPower = oldPower
	hum.MaxSlopeAngle = oldAngle
	
	debounce = false
	doubleJumpDisabler.Disabled = false
	
	print(trigger)
end

local function update(dt)
	if (debounce and hrp and hrp.Velocity.Magnitude <= .5) then
		stopSlide(player.Name.." stopped sliding by "..hrp.Velocity.Magnitude)
	end
end

local function stopSlideCheck()
	if (debounce and hrp) then
		stopSlide(player.Name.." stopped sliding")
	end
end
	
----------------
-- Inputs
----------------

UserInput.InputBegan:Connect(function(input, gameProcessed)
	if (input.UserInputType == Enum.UserInputType.Keyboard and hrp) then
		if (input.KeyCode == Enum.KeyCode.LeftControl and not gameProcessed or input.KeyCode == Enum.KeyCode.C and not gameProcessed) then
			slideRequest();
		end
	end
end)

UserInput.InputEnded:Connect(function(input, gameProcessed)
	if (input.UserInputType == Enum.UserInputType.Keyboard and hrp) then
		if (input.KeyCode == Enum.KeyCode.LeftControl and not gameProcessed or input.KeyCode == Enum.KeyCode.C and not gameProcessed) then
			stopSlideCheck();
		end
	end
end)

game:GetService("RunService").RenderStepped:Connect(update)

The LocalScript is located into a folder at StarterCharacterScripts.

image
I’ve added some checks for the script and it seems to print everything correctly. You can see that it actually finds the HumanoidRootPart.

image

Maybe it’s because the parent is Workplace instead of Player’s Character model when you are using :WaitForChild(“HumanoidRootPart”)? The image shows it’s Workplace:WaitForChild(“HumanoidRootPart”)

If you put this yield on purpose to attempt to ensure all implicit instances have loaded, then you might as well do this:

repeat wait() until game:IsLoaded() 
-- code

This doesn’t make sense since if the character doesn’t exist it’ll yield till it does, the third check is pointless.

Specify a timeOut

local hrp = char:WaitForChild("HumanoidRootPart", 5)

WaitForChild doesn’t consume any budget when the object exists when indexing, by the way.

1 Like

I think as long as it’s found the warning doesn’t matter so you can put :WaitForChild(‘HumanoidRootPart’, 10) for example and once it waits for 10 seconds it will just end, giving you no warnings.