Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Getting concatenate error with my script that for custom chat, why? help me!

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

2 comments

0

You probably meant to use OnServerEvent

0

I changed my answer up as Kirot was correct.

1 answer

✓ Accepted answer

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)

9 comments

0

not working :P

0

Oh, what about the parenting thingie

0

You didn't even correct the actual issue, which is OP using OnClientEvent and expecting it to handle FireServer()

0

Welp I should've mentioned that I still am cruddy at the client-server communications oof

0

Went back to check on one I helped resolve: https://scriptinghelpers.org/questions/71817/how-can-i-make-my-fe-tool-giver-work-giving-a-tool-to-the-client#68110 | And I did find I was wrong about what I did, I rewrote a better version though.

0

By what I think, You don't know what you are doing.

0

I'll be honest, I half-don't know what I'm doing.

0

its still not working :P

0

welp I tried, I'll fix up my answer.

This discussion is preserved as it was. New answers, comments, and votes are closed.