Can't send string value to server through a remote event

Hello! In a game I am working on a global announcement system, where certain players can type into a text box and click a button to have that text show up on an announcement. However, this system doesn’t seem to be working and it’s because of an issue with a remote event. I’m not super familiar with them so I’m not proficient in using them.

In a local script in the button to send the text, I have this:

script.Parent.Activated:Connect(function()
	game.ReplicatedStorage.AnnouncementEvent:FireServer(script.Parent.Parent.TextBar.Text)
end)

Where TextBar is the box that the player can type in.

In a server script that is under the screen gui:

local frame = script.Parent.GlobalAnnouncement
local pos1 = UDim2.fromScale(0.053, 0.299)
local pos2 = UDim2.fromScale(-0.3, 0.299)

game.ReplicatedStorage.AnnouncementEvent.OnServerEvent:Connect(function(text)
	script.Parent.GlobalAnnouncement.Body.Text = text
	frame:TweenPosition(pos1, "Out", "Quint", 3)
	wait(12)
	frame:TweenPosition(pos2, "In", "Quint", 3)
end)

Which gives me this error message:
10:13:10.856 Players.uhnruly.PlayerGui.GrandGui.ServerAnnouncements:6: invalid argument #3 (string expected, got Instance) - Server - ServerAnnouncements:6

I have verified that the remote event is sending, I changed line 6 to equal an actual string instead of a variable and the announcement worked correctly in that scenario once the event was fired. Past that, I’m not really sure what to do. How can I get the text to send as a string?

The first argument of OnServerEvent is always the player that fired the event, then any new parameters

game.ReplicatedStorage.AnnouncementEvent.OnServerEvent:Connect(function(plr, text) -- player first, then text
	script.Parent.GlobalAnnouncement.Body.Text = text
	frame:TweenPosition(pos1, "Out", "Quint", 3)
	wait(12)
	frame:TweenPosition(pos2, "In", "Quint", 3)
end)
3 Likes

I guess you also got the event wrong when the player clicks the button inside of the local Script. It must be:

local button = -- your path to the button

button.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.AnnouncementEvent:FireServer(script.Parent.Parent.TextBar.Text)
end)
1 Like