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

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

Asked by 4 years ago

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

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

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
Ad

Answer this question