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:

while true do
    wait()
    local alive = game.Teams.Survivors:GetPlayers()
    if script.Parent.PlayersLeft.Value == 1 then
        local name = alive.Name
        script.Parent.GameStatus.Value = name .. "won the game!"
    end
end
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.

while true do
        wait()
        local alive = game.Teams.Survivors:GetPlayers()
        if script.Parent.PlayersLeft.Value == 1 then
            local name = alive[1].Name
            script.Parent.GameStatus.Value = name .. "won the game!"
        end
    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.

while true do
        wait()

          if script.Parent.PlayersLeft.Value == 1 then
                local teams = game:GetService('Teams')

        for _, player in pairs(teams['Survivors']:GetPlayers()) do
                 print(player.Name)
        end
        end
end
0
I feel like such an idiot for not suggesting that. fxrtifyy 0 — 4y

Answer this question