Ad
Log in to vote
1

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

Asked by
enes223 312 Moderation Voter
3 years ago
Edited 3 years ago

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

0
You probably meant to use OnServerEvent Kiriot22 3227 — 3y
0
I changed my answer up as Kirot was correct. Cvieyra2test 176 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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)

0
not working :P enes223 312 — 3y
0
Oh, what about the parenting thingie Cvieyra2test 176 — 3y
0
You didn't even correct the actual issue, which is OP using OnClientEvent and expecting it to handle FireServer() Kiriot22 3227 — 3y
0
Welp I should've mentioned that I still am cruddy at the client-server communications oof Cvieyra2test 176 — 3y
View all comments (5 more)
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. Cvieyra2test 176 — 3y
0
By what I think, You don't know what you are doing. greatneil80 2612 — 3y
0
I'll be honest, I half-don't know what I'm doing. Cvieyra2test 176 — 3y
0
its still not working :P enes223 312 — 3y
0
welp I tried, I'll fix up my answer. Cvieyra2test 176 — 3y
Ad

Answer this question