SinClosed
(LK_Lulen)
February 2, 2022, 11:36pm
#1
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!
FunAsiK
(FunAsiK)
February 2, 2022, 11:47pm
#2
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.
Forummer
(Forummer)
February 2, 2022, 11:59pm
#3
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.
SinClosed
(LK_Lulen)
February 3, 2022, 11:44pm
#4
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
Sarchyx
(Sarchyx)
February 4, 2022, 3:47am
#6
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
SinClosed
(LK_Lulen)
February 5, 2022, 1:02am
#7
it doesnt work either! gives me the same error
FunAsik Solution did work for me tho what is the code that give this error
SinClosed
(LK_Lulen)
February 5, 2022, 3:34am
#9
ServerScriptService.Script:367: attempt to index number with number is the error im getting
SinClosed
(LK_Lulen)
February 5, 2022, 3:35am
#10
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?)
SinClosed
(LK_Lulen)
February 5, 2022, 3:46am
#12
I tried his code already but it didn’t work it gave same error
SinClosed
(LK_Lulen)
February 5, 2022, 4:01am
#13
Sorry just had some very common issues so yeah thanks FunAsiK