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

Infinite yield with WaitForChild issue... Any clue?

Asked by 4 years ago
Edited 4 years ago

I have an issue with the WaitForChild function. When I use It to get a character's object, I freezes and returns this:

Infinite yield possible on 'SnyFort:WaitForChild("LowerTorso")

So these are the parts of the code that cause this:

Server script

players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        remoteEvent:FireClient(player,"setUpPlayer")
    end)
end)

Local Script (Starter player script)


local status = "dead" local torso = nil local root = nil local rightShoulder = nil local leftShoulder = nil local neck = nil local upperTorso = nil local humanoid = nil function setUpPlayer() local char = player.Character or player.CharacterAdded:wait() torso = char:WaitForChild("LowerTorso") root = char:WaitForChild("HumanoidRootPart") rightShoulder = char:WaitForChild("RightUpperArm").RightShoulder leftShoulder = char:WaitForChild("LeftUpperArm").LeftShoulder neck = char:WaitForChild("Head").Neck upperTorso = char:WaitForChild("UpperTorso").Waist humanoid = char:WaitForChild("Humanoid") status = "none" humanoid.Died:Connect(function() status = "dead" humanoid.Parent:Destroy() end) end local functionList = { setUpPlayer = setUpPlayer } local function onNotifyPlayer(func,...) functionList[func](unpack({...})) end remoteEvent.onClientEvent:Connect(onNotifyPlayer)

This is how It works: everytime the player respawns, the servers sends them an event to execute the function "setUpPlayer". This function simply fills up each variable.

I've tested It, and It works the first time the character spawns.However,if you reset and respawn, the scripts gets stuck at the first WaitForChild call. And at first sight, It makes no sense, since the CharacterAdded function confirms the character is fully loaded.

Any ideas? Thanks

Edit: I forgot to add the "humanoid.Parent:Destroy()" line.

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Is your player R15 or R6? Your character should be R15 for this to work. Also, on line 38 you said remoteEvent.onClientEvent:Connect(onNotifyPlayer). I'm pretty sure it should be OnClientEvent, not onClientEvent.

0
Yes, It works with R15. And both OnClientEvent and onClientEvent work masterjosue1998 116 — 4y
0
Try looking at masterjosue1998's answer. youtubemasterWOW 2741 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Just changed the line local char = player.Character or player.CharacterAdded:wait() to local char = player.CharacterAdded:wait() and now It works fine... Have no idea why though

Answer this question