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

Any better methods then using chr:WaitForChild?

So, Whenever the player dies (not by reseting) the output shows "Infinite Yield Possible "Workspace.PlayerNameHere.WaitForChild("Disabled") Basically saying that it will go for forever, Any other way other then using "chr:WaitForChild"? That is better and that so this error doesnt show up? Or how to fix this issue? Also, Whenever the player dies again, another one shows up. Basically saying: Infinite Yield Possible "Workspace.PlayerNameHere.WaitForChild("Disabled") again, then if the player dies again a third one pops up, etc etc.

local plr = game:GetService("Players").LocalPlayer
repeat
	wait()
until plr.Character and plr.Character.Humanoid
local chr = plr.Character
local human = chr.Humanoid
local hrp = chr.HumanoidRootPart
mouse = plr:GetMouse()
cam = workspace.CurrentCamera


local disabled = chr:WaitForChild("Disabled")

4 comments

0

Ask me if you need any more code or info

0

you could always just wrap it in a pcall function

1

Infinite yield possible means that no child named Disabled will ever be added. You can fix this by adding a child to the character named Disabled or add a number after "Disabled" to give it a maximum yield time

0

"Will ever be added", what if it is added later..... smh

1 answer

Yeah, you should use Player.CharacterAdded event to catch the Character again and reset variable references to the new character. You can also reset local scripts on respawn.

LocalPlayer.CharacterAdded:Connect(function(character)
	local humanoid = character:WaitForChild("Humanoid") 
	-- etc
end)

4 comments

0

This could work for server scripts too if you've obtained the player through something like Players.PlayerAdded

0

Would this replace: local plr = game:GetService("Players").LocalPlayer i had it in the code, but i didnt think i needed to mention it

0

also tnow i think this is the part of the code i need to replace i edited the post if the comment i post you cant read correctly.: if i put it where the --etc would go it just displays hil

0

local plr = game:GetService("Players").LocalPlayer repeat wait() until plr.Character and plr.Character.Humanoid local chr = plr.Character local human = chr.Humanoid local hrp = chr.HumanoidRootPart mouse = plr:GetMouse() cam = workspace.CurrentCamera

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