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
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 ._.
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
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