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 comments
Yes, It works with R15. And both OnClientEvent and onClientEvent work
Try looking at masterjosue1998's answer.