I have a script that is supposed to add one win and 100 coins to the winner after the round is over. I know that the part of the script that checks to see if there is less than two players in the team "Players" works, but the output console keeps showing the error "plrs1 is not a valid member of Players". If anyone can point me in the right direction that would be great! Here's my script:
local plrs1 = game.Teams.Playing:GetPlayers() if #plrs1 < 2 then t = 1 local wins = game.Players.plrs1.leaderstats.wins wins.Value = wins.Value + 1 local coins = game.Players.plrs1.leaderstats.coins coins.Value = coins.Value + 100 end
By using .plr1
, you’re trying to ascend into the Players
container, to verify two things: Is there a Player Object called "plr1", or is there a property called "plr1"? Both of which effectively are false which is raising your invalid
exception. To actively filter for something as an Object, you have to concatenate it in via square braces.
game.Players[plr1]
But the issue doesn't stop here, :GetPlayers()
returns an array of Player Objects, meaning you're trying to look for a table as a Player. Instead—and since it's a table, we can use a pairs
loop to iterate over each Player Object within the array, and manipulate them one-by-one
local Teams = game:GetService("Teams") local Playing = Teams.Playing:GetPlayers() if (#Playing < 2) then for _,Player pairs(Playing) do local Wins = Player.leaderstats.wins local Coins = Player.leaderstats.coins Wins.Value,Coins.Value = (Wins.Value + 1), (Coins.Value +100) end end