Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

5 comments

0

Are you trying to change the text of a TextLabel? If so, use .Text instead of .Value

0

Not a textlabel, just a StringValue

0

I think I know the problem, you're getting the players of a team, and trying to see the name of it.

0

yes thats the idea but it only gets the one in the team from the if statemenbt

0

I answered it. You'tre trying to get a table, and trying to see the name of the table instead of the player.

2 answers

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.

7 comments

0

another error: Workspace.GameManager.Findwinner:5: attempt to index nil with 'Name'

0

Change :GetPlayers() to :GetChildren()

0

Its the same error.

0

Hmm.. Is it a localscript or a server script?

0

server

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.

0

I FIXED IT, CHECK MY ANSWER!!! WOOH :D

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

1 comment

0

I feel like such an idiot for not suggesting that.

This discussion is preserved as it was. New answers, comments, and votes are closed.