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

My for loop doesn't work, saying I can't call an instance?

Code:

	for _, player in game.Players do
		if (player.Team.Name == "Contestant" and player.Answer.Value ~= answer) then
			player.Team = game.Teams.Eliminated
			player:LoadCharacter()
			player.Answer.Value = ""
		end
	end

What the code is supposed to do is go through every player, check if they are on the Contestant team and got the answer wrong, and respawn them, change their team, and reset their answer value. The first line (for) is failing, saying that I tried calling an instance (or something close to that)

1 answer

✓ Accepted answer

Do you know how to loop over the players ? Because this is not how you do it.

this is how you do it

local players = game:GetService("Players")

for _, player in pairs(players:GetPlayers()) do
    if (player.Team.Name == "Contestant" and player.Answer.Value ~= answer) then
        player.Team = game.Teams.Eliminated
        player:LoadCharacter()
        player.Answer.Value = ""
    end
end

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