Can't get the player name to a text label

So i’m still making a quiz game where the player names should be written on a board when they answer correctly but i have an issue with getting the player’s names. I made a list of winners and events to kind of transmit the names to the board (i don’t really know what im doing because thats my first game but I watched a lot of tutorials) but when i run the code i only get " answered correctly" and no names appear.

I already did this:

local PlayerName = Player.Name

local winners = {}

if guess == Word then
table.insert(winners, PlayerName)
print(PlayerName)
Rep.Won:FireServer(winners)
end

In the other script:

local Won = ReplicatedStorage:WaitForChild(‘Won’)

Won.OnServerEvent:Connect(function(winners)
ReplicatedStorage.Won:FireAllClients(winners)

end)

and in the third script:

Won.OnServerEvent:Connect(function(winners)
table.insert(Winners, winners)
textLabel.Text = table.concat(Winners, ", ") … “answered correctly”

	end)
1 Like

what is the output you got in the script and what is “Player” on the “PlayerName” Variable

local PlayerName = Player.Name

local winners = {}

if guess == Word then
table.insert(winners, PlayerName)
print(PlayerName)
Rep.Won:FireServer(winners)
end

In the other script:

local Won = ReplicatedStorage:WaitForChild(‘Won’)

Won.OnServerEvent:Connect(function(winners)
ReplicatedStorage.Won:FireAllClients(winners)

end)

and in the third script:

Won.OnServerEvent:Connect(function(winners)
table.insert(Winners, winners)
textLabel.Text = table.concat(Winners, ", ") … “answered correctly”
end)

In the output it actually gives me the player name. And Player isn’t anything actually. I just googled how to get a player’s name and it said : write ‘Player.Name’ so i did it ._.

you need to make a stringvalue at replicatedstorage and make that when the value change the text changes, and at the Won event:

Won.OnServerEvent:Connect(function(winners)
table.insert(Winners, winners)
textLabel.Text = table.concat(Winners, ", ") … “answered correctly”
end)

say “print(winners)” before you start the code
and tell me what it prints

I think i don’t really understand what you mean. What string value in replicated storage? Why?

just forget about it

but what did the output said when you printed “winners”

and the reason is, that it is better.

It says nothing. Before i wrote it it said my name but now i don’t get anything

already made the variable of:
game.Players.LocalPlayer?

local Player = game.Players.LocalPlayer
local PlayerName = Player.Name


i think the problem is that
you are running the event 2 times in a script

local Won = ReplicatedStorage:WaitForChild(‘Won’)

Won.OnServerEvent:Connect(function(winners) 
ReplicatedStorage.Won:FireAllClients(winners)
end)

and

Won.OnServerEvent:Connect(function(winners)
table.insert(Winners, winners)
textLabel.Text = table.concat(Winners, ", ") … “answered correctly”
end)

so, change the second one with this:

Won.OnClientEvent:Connect(function(winners)
table.insert(Winners, winners)
textLabel.Text =  tostring(winners)… “, answered correctly”
end)

oh and forgot change the first one to this

Won.OnServerEvent:Connect(function(plr,winners) 
ReplicatedStorage.Won:FireAllClients(winners)
end)

No but i get the name in the output anyway ? So idk

Actually idk what i did but i’m not even getting the " answered correctly" on the board… But im gonna try it out.

try it in such a way as it is like getting game.Players instead of game:GetService(“Players”) or I wouldn’t know

the problem is he is running onserverevent on client script and thats a big issue.

but how do I use that tostring that you put there because when i write it says “malformed string”?

um sorry but thats the best i could do

Ok thx anyway then i’m gonna try to figure it out

When you fire a remote event from client to server it adds a player argument to whatever arguments you send.
So in:

local PlayerName = Player.Name

local winners = {}

if guess == Word then
table.insert(winners, PlayerName)
print(PlayerName)
Rep.Won:FireServer(winners)
end

The server receives

Won.OnServerEvent:Connect(function(player, winners)
ReplicatedStorage.Won:FireAllClients(winners)

end)

So when you fire all clients in that same section of the script it is sending back nil

Your third script also fires, and receives a player argument

Won.OnServerEvent:Connect(function(winners)
table.insert(Winners, winners)
textLabel.Text = table.concat(Winners, ", ") … “answered correctly”

If you haven’t defined local Winners = {} in that script then the textLabel.Text will evaluate to "answered correctly" only.
From the code provided I’m really not sure what the second script is doing, and you should merge this with the third one to make sure you connect one server event which adds to the Winners table and updates the text.
In the local script you can get the player by
local player = game:GetService("Players").LocalPlayer
and so their name is obtained by player.Name (which is what you should add to the Winners table to make sure it comes out as a string).
I hope this helps.

and if i just wrote winners = {} in the text label script is it okay or should i add something ? and by the way i’m not even getting the “answered correctly” anymore so i guess i must’ve completely done something wrong

Sorry I meant doing something more like this

Local Winners = {}
Won.OnServerEvent:Connect(function(player)
table.insert(Winners, player.Name)
textLabel.Text = table.concat(Winners, ", ") … “answered correctly”
end

Why are you firing all clients the player who fired the event? this might be the issue. @jagoda9109