I am making a name system for my game. It makes a button for every name in the table, and it is supposed to change the value inside the player to the name that is pressed. I get an error saying "invalid argument #3(expected string, got instance)"
localscript inside the gui
01 | wait( 2.5 ) |
02 | local Button = game.ReplicatedStorage:WaitForChild( "Name" ) |
03 | local Frame = script.Parent |
04 | local Names = { "Arya" , "Amber" , "Imaaad" , "Rhiann" , "Atlanta" , "Aj" , "Noa" , "Romany" , "Layton" , "Cruz" , "Helen" , "Shannay" , "Mattew" , "Katerina" , "Subhaan" , "Joesph" , "Shaya" , "Tymoteusz" , "Taliyah" , "Mateo" , "Aimie" , "Irene" , "Naomi" , "Sorrel" , "Ptolemy" , "Mathilde" , "Nola" , "Amari" , "Zayd" , "Nick" , "Pauline" , "Adi" , "Corbyn" , "Lowenna" , "Ashwin" , "Emilio" , "Nathaniel" , "Yara" , "Aniqa" , "Zhen" , "Connel" , "Henry" , "Bob" , "Trevor" , "Ray" , "Suzy" , "Devante" , "Chantal" , "Bryn" , "Cariad" , "Juliet" , "Leila" } |
05 | local player = game.Players.LocalPlayer |
06 |
07 | for i,v in pairs (Names) do |
08 | local copy = Button:Clone() |
09 | copy.Name = v |
10 | copy.Text = v |
11 | copy.Parent = Frame |
12 | end |
13 |
14 | while wait( 0.01 ) do |
15 | for i,v in pairs (Names) do |
ServerScript that is supposed to change the value
1 | game.ReplicatedStorage.NameEvent.OnServerEvent:Connect( function (player, ChosenName) |
2 | local Name = player:FindFirstChild( "PlayerName" ) |
3 | Name.Value = ChosenName |
4 | end ) |
Client
01 | wait( 2.5 ) |
02 | local Button = game.ReplicatedStorage:WaitForChild( "Name" ) |
03 | local Frame = script.Parent |
04 | local Names = { "Arya" , "Amber" , "Imaaad" , "Rhiann" , "Atlanta" , "Aj" , "Noa" , "Romany" , "Layton" , "Cruz" , "Helen" , "Shannay" , "Mattew" , "Katerina" , "Subhaan" , "Joesph" , "Shaya" , "Tymoteusz" , "Taliyah" , "Mateo" , "Aimie" , "Irene" , "Naomi" , "Sorrel" , "Ptolemy" , "Mathilde" , "Nola" , "Amari" , "Zayd" , "Nick" , "Pauline" , "Adi" , "Corbyn" , "Lowenna" , "Ashwin" , "Emilio" , "Nathaniel" , "Yara" , "Aniqa" , "Zhen" , "Connel" , "Henry" , "Bob" , "Trevor" , "Ray" , "Suzy" , "Devante" , "Chantal" , "Bryn" , "Cariad" , "Juliet" , "Leila" } |
05 |
06 | -- i is unused, but I'm doing this in visual studio code with selene. |
07 | for _, v in pairs (Names) do |
08 | local copy = Button:Clone() |
09 | copy.Name = v |
10 | copy.Text = v |
11 | copy.Parent = Frame |
12 | end |
13 |
14 | -- Don't use while loops with connections unless you know what you're doing. |
15 | -- It can result in the event being fired >100 times. |
Server
1 | -- VSC formatting, don't blame me. |
2 | game.ReplicatedStorage.NameEvent.OnServerEvent:Connect( |
3 | function (player, ChosenName) |
4 | -- Player is the first argument that is given when a remote event is fired, the rest are arguments YOU fire. |
5 | local Name = player:FindFirstChild( "PlayerName" ) |
6 | Name.Value = ChosenName |
7 | end |
8 | ) |