I'm trying to make custom chat for my game and getting this error: attempt to concatenate local 'text'... ;-; Heres scripts I made:
For Send Button:
script.Parent.MouseButton1Click:Connect(function() local text = script.Parent.Parent.TextBox.Text local PlrName = game.Players.LocalPlayer.Name game.ReplicatedStorage.Message:FireServer(PlrName, text) end)
For Label:
game.ReplicatedStorage.Message.OnClientEvent:Connect(function(PlrName, text) script.Parent.Text = PlrName..": "..text end)
If you help me i will send my thanks so much...
Well one problem I could find right away is that the Client-Server communication actually gives 3 arguments and not the two you specified.
All client-server communications that are utilized with the Event object provide the player itself.
So you can remove the "PlrName" argument and just utilize the player's name, here's a rework:
Edit: Kirot is right, I did a big booboo on this one rip. As he mentions in a comment, we should've done "OnServerEvent" instead.
Send Button:
script.Parent.MouseButton1Click:Connect(function() local text = script.Parent.Parent.TextBox.Text game.ReplicatedStorage.Message:FireServer(text) end)
Label: (Ignore this one, it was a failure RIP)
game.ReplicatedStorage.Message.OnClientEvent:Connect(function(player, text) local PlrName = player.Name script.Parent.Text = PlrName..": "..text end)
Rewrite of Label (This one doesn't work either rip):
game.ReplicatedStorage.Message.OnServerEvent:Connect(function(player, text) local PlrName = player.Name script.Parent.Text = PlrName..": "..text end)
As for the text issue, it should've just returned the player's name. Are you sure the Send Button is the secondary or first parent of the script?
What I mean is:
Secondary Parent:
script --> 1st Parent --> SendButton (This is how it's working right now)
First Parent:
script --> SendButton (How I think it'll need to work like)