Attempt to get length of a number value?

Hello!
I want the winner to go back to the players team.
However, I have an error “attempt to get length of a number value”…
Heres the code:

local winner =  #game.Teams.Winner:GetPlayers()
local winnerFr = winner[math.random(1, #winner)]
winnerFr.Team = game.Teams.Playing

What’s wrong here?
Thanks!

This should work:

local winner =  game.Teams.Winner:GetPlayers()
local winnerFr = winner[math.random(#winner)]
winnerFr.Team = game.Teams.Playing

The error is that you are trying to get the length of the player.

The error is that “winner” was already assigned the length of the array returned by “game.Teams.Winner:GetPlayers()” and he was attempting to get the length of that length inside the “math.random()” call, your solution is correct though.

It’s not working! It just gives this error:

ServerScriptService.Script:367: attempt to get length of a number value 

Your problem is like what @Forummer said you try to get length of the length change this line

To

local winnerFr = winner[math.random(1,winner)]

EDIT: Wrong post reply srry FunAsik
Edit2: I made some mistake do what FunAsik Suggest sorry tho

That will not work since here winner variable is a number, not a table, so you’ll not be able to index values. Necessarily OP should change winner variable to what FunAsiK suggested.

1 Like

it doesnt work either! gives me the same error

FunAsik Solution did work for me tho what is the code that give this error

ServerScriptService.Script:367: attempt to index number with number is the error im getting

local winner =  #game.Teams.Winner:GetPlayers()
				local winnerFr = winner[math.random(winner)]
				winnerFr.Team = game.Teams.Playing

This is my code ^

You use FunAsik code and it still give error?

^ this one (Have you missed something?)

I tried his code already but it didn’t work it gave same error

Sorry just had some very common issues so yeah thanks FunAsiK