Elseif statement doesn't work

Hello everyone, I’m experimenting with randomly selecting roles for players. Three roles are in ReplicationStorage and one of the random ones appears in the player. But there is a problem: if the player is given a second role, then the elseif block is not executed; Instead, a warning is written in the console: Infinite yield possible on ‘Workspace.SCILEME:WaitForChild(“FunnyMan”)’. And if the first role is chosen, then everything is in order. I will be very grateful for your help. Here are the scripts:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Wait()
	
	local RandomRoles = game.ReplicatedStorage:WaitForChild("Roles"):GetChildren()
	local Randomizer = RandomRoles[math.random(1, #RandomRoles)]
	Randomizer.Parent = player.Character
end)

This is server script it randomly selects a role and places it in the player

if game.Players.LocalPlayer.Character:WaitForChild("FunnyMan") then
	print("Funny")
elseif game.Players.LocalPlayer.Character:WaitForChild("NeutralMan") then
	print("Neutral")
elseif game.Players.LocalPlayer.Character:WaitForChild("BoredMan") then
	print("Bored")
end

This is a local script that checks what role the player currently has (An error occurs here)

Is “FunnyMan” an instance being placed under the player’s character? Infinite Yield means the code could yield forever because it doesn’t exist. Also, why use WaitForChild?

Today I brake well. Instead of WaitForChild, I used FindFirstChild and it worked. Sorry for my stupidity…

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.