Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Need help with error while changing value. Does anyone have a solution to this error?

Asked by
Ghost40Z 118
3 years ago

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

01wait(2.5)
02local Button = game.ReplicatedStorage:WaitForChild("Name")
03local Frame = script.Parent
04local 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"}
05local player = game.Players.LocalPlayer
06 
07for i,v in pairs(Names) do
08    local copy = Button:Clone()
09    copy.Name = v
10    copy.Text = v
11    copy.Parent = Frame
12end
13 
14while wait(0.01) do
15    for i,v in pairs(Names) do
View all 25 lines...

ServerScript that is supposed to change the value

1game.ReplicatedStorage.NameEvent.OnServerEvent:Connect(function(player, ChosenName)
2    local Name = player:FindFirstChild("PlayerName")
3    Name.Value = ChosenName
4end)

1 answer

Log in to vote
1
Answered by
notfenv 171
3 years ago

Client

01wait(2.5)
02local Button = game.ReplicatedStorage:WaitForChild("Name")
03local Frame = script.Parent
04local 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.
07for _, v in pairs(Names) do
08    local copy = Button:Clone()
09    copy.Name = v
10    copy.Text = v
11    copy.Parent = Frame
12end
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.
View all 29 lines...

Server

1-- VSC formatting, don't blame me.
2game.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)
0
Thanks! It worked lol. Ghost40Z 118 — 3y
Ad

Answer this question