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

Script that finds the winner doesn't wanna display their name, any fix?

Asked by 4 years ago

Error: Workspace.GameManager.Findwinner:6: attempt to concatenate nil with string

Code:

1while true do
2    wait()
3    local alive = game.Teams.Survivors:GetPlayers()
4    if script.Parent.PlayersLeft.Value == 1 then
5        local name = alive.Name
6        script.Parent.GameStatus.Value = name .. "won the game!"
7    end
8end
0
Are you trying to change the text of a TextLabel? If so, use .Text instead of .Value fxrtifyy 0 — 4y
0
Not a textlabel, just a StringValue Aeroporia 37 — 4y
0
I think I know the problem, you're getting the players of a team, and trying to see the name of it. fxrtifyy 0 — 4y
0
yes thats the idea but it only gets the one in the team from the if statemenbt Aeroporia 37 — 4y
0
I answered it. You'tre trying to get a table, and trying to see the name of the table instead of the player. fxrtifyy 0 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

You're getting a table, and trying to see the name of it.

1while true do
2        wait()
3        local alive = game.Teams.Survivors:GetPlayers()
4        if script.Parent.PlayersLeft.Value == 1 then
5            local name = alive[1].Name
6            script.Parent.GameStatus.Value = name .. "won the game!"
7        end
8    end

I'm pretty sure this is the solution.

0
another error: Workspace.GameManager.Findwinner:5: attempt to index nil with 'Name' Aeroporia 37 — 4y
0
Change :GetPlayers() to :GetChildren() fxrtifyy 0 — 4y
0
Its the same error. Aeroporia 37 — 4y
0
Hmm.. Is it a localscript or a server script? fxrtifyy 0 — 4y
View all comments (3 more)
0
server Aeroporia 37 — 4y
0
I did a test to print the alive variable and got something completely unexpected " table: 0x5a1815269514e5c4" the end random number was completely different each time. Aeroporia 37 — 4y
0
I FIXED IT, CHECK MY ANSWER!!! WOOH :D Aeroporia 37 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

I ended up just using a different strategy with for I, v in pairs technique. AND IT WORKED.

01while true do
02        wait()
03 
04          if script.Parent.PlayersLeft.Value == 1 then
05                local teams = game:GetService('Teams')
06 
07        for _, player in pairs(teams['Survivors']:GetPlayers()) do
08                 print(player.Name)
09        end
10        end
11end
0
I feel like such an idiot for not suggesting that. fxrtifyy 0 — 4y

Answer this question