How do I send a parameter into a Remote Event script?

I am trying to make a thing where the player inputs text, sends it to the server, and replicates it to clients. But when the player pushes the button after they insert text, the local script grabs that textbox’s text and sends it to a script to handle a remote event. The way I try to make the text appear is different but I am trying to grab the Textlabel to put the input text in, the textbox inputted text and the time to go through each letter to appear. So how do I get those and send it to the script to make in the parameter?

Local script

local TextLabel = script.Parent.TextLabel
local TextBox = script.Parent.TextBox
local sendmsg = game.ReplicatedStorage:WaitForChild("SendMessageToServer")

script.Parent.TextButton.MouseButton1Click:Connect(function()
	sendmsg:FireServer() -- I need to try to get the items to send the script
end)

Server Script (To handle the remote event and send the text to the TextLabel)

local SendMessageToServer = Instance.new("RemoteEvent")
SendMessageToServer.Name = "SendMessageToServer"
SendMessageToServer.Parent = game.ReplicatedStorage
local TypeSound = game.StarterGui.ScreenGui.Frame5.TextLabel
local TextLabel = script.Parent.TextLabel
local TextBox = script.Parent.TextBox


local function sendmsg(object,text,length)
	for i = 1,#text,1 do
		object.Text = string.sub(text,1,i)
		wait(0.05)
		TypeSound:Play()
	end
end
SendMessageToServer.OnServerEvent:Connect(function(player, Textbox)
	sendmsg(label,box,time) -- (Where to put the text, Where to get text from, time to go through letters.
 (I need the local script to send me this info so it can replicate to the other clients)
end)

SendMessageToServer.OnServerEvent:Connect(sendmsg)

Could someone try to help me, please? I hope I explained it well enough but basically, I just need the local script to send me the info needed to have the server print the input text into all other clients on the label in the parameters.

1 Like

local script

local TextLabel = script.Parent.TextLabel
local TextBox = script.Parent.TextBox
local sendmsg = game.ReplicatedStorage:WaitForChild("SendMessageToServer")

script.Parent.TextButton.MouseButton1Click:Connect(function()
	sendmsg:FireServer(TextLabel, TextBox.Text)
end)

server script

local SendMessageToServer = Instance.new("RemoteEvent")
SendMessageToServer.Name = "SendMessageToServer"
SendMessageToServer.Parent = game.ReplicatedStorage
local TypeSound = game.StarterGui.ScreenGui.Frame5.TextLabel
local TextLabel = script.Parent.TextLabel
local TextBox = script.Parent.TextBox


local function sendmsg(object, text)
	for i = 1,#text,1 do
		object.Text = string.sub(text,1,i)
		wait(0.05)
		TypeSound:Play()
	end
end
SendMessageToServer.OnServerEvent:Connect(function(Label, Text)
	sendmsg(Label, Text)
end)

1 Like

To get whatever text the user typed into the textbox, inside your :FireServer() call, you would just do “Textbox.Text”, and that’ll send the textbox’s text over to the server.

Thanks for the reply. I put this in my code and put a few prints to see if it is working. The print function worked when I pressed the button. And I added a check in the Server script and put an OnServerEvent function to see if the print inside that would work and it did not. Is this the right thing to use to see if it did get sent?

OnServerEvent from player will always assign first parameter as a player, so in onserverevent you should instead of (Label, Texbox) do (Player, Label, Textbox)

First or all instead of creating remote inside the script you have to create it manually in studio. Second -

Local script

local Textbox = textbox
local Label = label

local Remote = remoteevent

Textbutton.Activated:Connect(function()
        local TextboxText = Textbox.Text
        Remote:FireServer(Label, TextboxText)
end)


Server script

Remote.OnServerEvent:Connect(function(player, Label, TextboxText)
print(Label, TextboxText)
end)
1 Like

Local Script

local Label = script.Parent.TextLabel
local Textbox = script.Parent.TextBox

local Remote = game:GetService("ReplicatedStorage"):WaitForChild("SendMsg")

script.Parent.TextButton.MouseButton1Click:Connect(function()
	print("Sent")
	local TextboxText = Textbox.Text
	Remote:FireServer(Label, TextboxText)
end)

Server Script

local Remote = game:GetService('ReplicatedStorage').SendMsg
local TypeSound = game.StarterGui.ScreenGui.Frame5.TextLabel
local TextLabel = script.Parent.TextLabel
local TextBox = script.Parent.TextBox


local function sendmsg(object,text,length)
	print("Check 1")
	for i = 1,#text,1 do
		object.Text = string.sub(text,1,i)
		wait(0.05)
		TypeSound:Play()
	end
end

Remote.OnServerEvent:Connect(function(player, Label, TextboxText)
	print("Received")
	print(TextboxText)
	--sendmsg(Label, TextboxText)
end)

It only printed “Sent” and not " Received" which I think it is supposed to do. Trying to print send and received to make sure the command is going through to the server script. Is this the correct thing? Thanks for the reply.

1 Like

i have no idea why it doesn’t work, try to change variable in local script to game.ReplicatedStorage.SendMsg

1 Like

I set all the things referring to “Remote” directly to the SendMsg event and still same output as before printing only “Sent”.

1 Like

Maybe puttin onserverevent above the local function?

1 Like

Also wheres the server script is exactly

The script is in Server script service and putting the onserverevent over the function did not change anything

Maybe you have disabled the script? Also try to create new server script and use the new one instead of what you’re using rn

I create a new script and pasted the code into it and the same output nothing changed

Damn that’s weird, try to search solutions thru devforum

Also try changing the MouseButton1Click to Activated

Yeah, nothing changed. Anyways I will try to find solutions for this issue later. And thank you for the help

1 Like

I’ll reply if i’ll find any solution

1 Like

Hmmm, does your output shows server messages when playing in studio?

You should put your print(“Sent”) statement after you call “FireServer()”, so you know that you actually sent the information to the server. Right now all your print statement does is tell you if the player clicked the TextButton.