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

Any better methods then using chr:WaitForChild?

Asked by 4 years ago
Edited 4 years ago

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")
0
Ask me if you need any more code or info BrandonXYZ9 18 — 4y
0
you could always just wrap it in a pcall function jediplocoon 877 — 4y
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 thatwalmartman 404 — 4y
0
"Will ever be added", what if it is added later..... smh greatneil80 2647 — 4y

1 answer

Log in to vote
0
Answered by
Psudar 882 Moderation Voter
4 years ago
Edited 4 years ago

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)
0
This could work for server scripts too if you've obtained the player through something like Players.PlayerAdded Psudar 882 — 4y
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 BrandonXYZ9 18 — 4y
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 BrandonXYZ9 18 — 4y
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 BrandonXYZ9 18 — 4y
Ad

Answer this question