I want to make a system where a player types into a textbox and can send to the whole group once they press the imagebutton on the right or it. The problem is I want to send the info for this message into a StringValue in ReplicatedStorage, and I’m not sure how to do it.
So far I’ve tried RemoteEvents and RemoteFunctions.
You could add a StringValue into ReplStorage, however a change at the client won’t replicate to all players. The easiest way I find, is to fire a remote event to the server with the string value you want to send. Then for the server to update the StringValue into ReplStorage, for which the clients have a StringValue.Changed and then update accordingly.
I’m mainly trying to figure out how to get the script in ServerScriptService which references the RemoteEvent how to get the player’s Text in the Textbox. Here’s what I have so far.
Good start. The client always sends the Player name with FireServer, you just need to send other data with it in your LocalScript. For example:
-- LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Chatted= ReplicatedStorage.cb3
local remoteString = ReplicatedStorage.remoteString -- a StringValue object you need to add
local textString = "Woohoo, string sent from player" -- Change this to what you want sent from a button, or text box, etc.
Chatted:FireServer(textString) -- Sends the player and value to the server
remoteString.Changed:Connect(functions(sentString) -- Monitors a value in ReplStorage
print("We were sent: " .. sentString)
)
Then in a Server script, we receive it from Client and update the value in ReplStorage:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Chatted= ReplicatedStorage.cb3 --Your RemoteEvent
local remoteString = ReplicatedStorage.remoteString -- a StringValue object you need to add
Chatted.OnServerEvent:Connect(function(plr, textString)
print("Player ", plr, "sent ", textString)
local stringToSend = "Player ".. plr.. "sent ".. textString
remoteString.Value = textString
end)
That should cover the logic of it. Some would say to use RemoteFunctions for sending to the Clients to display the chatted string. The above is just hand written and not tested, so you may need to debug it a bit.