Is it possible to make when I press a button everything I wrote in my textlabel will be shown to a random person in a team

ok thx so were should i put the scripts

This took way too long to type just because of how I was gonna attempt to figure out how I’d make this work but w h a t e v e r

If for some reason you still have an issue, open this up:

--This should be parented inside your TextBox hopefully as a LocalScript
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

local TextBox = script.Parent

TextBox.FocusLost:Connect(function(EnterHit)
    if EnterHit then
        Event:FireServer(TextBox.Text)
    end
end)
--And this shall be your ServerScript to handle the Text Transfer >:O
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local Teams = game:GetService("Teams")

Event.OnServerEvent:Connect(function(SentPlayer, DeliveredText)
    local SentTeam = SentPlayer.Team
    local RedPlayers = Teams.RedTeam:GetPlayers()
    local BluePlayers = Teams.BlueTeam:GetPlayers()
    
    local chosenTeam = SentTeam == Teams.RedTeam and BluePlayers or RedPlayers
    local RandomPlayer = chosenTeam[math.random(#chosenTeam)]
    if RandomPlayer then
        local NoteGui = RandomPlayer.PlayerGui:WaitForChild("NoteGui")

        NoteGui.Enabled = true
        NoteGui.TextLabel.Text = DeliveredText
        wait(5)
        NoteGui.Enabled = false
    end
end)

Do keep in mind though that you will need to define & assign these variables/properties by yourself, I’m just giving an example on how you can implement it

so wat is the note gui :thinking:

Basically the GUI that will appear on the Random Player’s screen & show the text you sent to

Have you even looked up the API Reference what

ok thank you I will test it out

if i wanted it to send after i pressed a button i would just make a local script in the button which enables the script?

You can just use the MouseButton1Click event connected to your TextButton to make it fire the Text of the TextBox when clicked

It depends on what scenario you’re really going for, TextBox’s FocusLost event will fire (In relation with the parameter) if you hit the enter key after you’re finishing typing on the box

For the button, just change it to a TextButton and detect it’s changes using MouseButton1Down instead

o ya smart ima do that :smile:

Since you seem like you are new to scripting in Roblox and are still using multiple scripts I’ll edit my answers accordingly.

In local script in a TextLabel:

-- The remote event
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("MessageEvent")

local TextLabel = script.Parent

-- function you use whenever you want to receive messages:
local function ReceiveMessage(text)
	TextLabel.Visible = true
	TextLabel.Text = text

	wait(30) -- The amount of time to wait to allow the player to read the message

	TextLabel.Visible = false
end

-- Calls ReceiveMessage whenever a message is received
RemoteEvent.OnClientEvent:Connect(ReceiveMessage)

In a local script in a TextBox:

-- The remote event
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("MessageEvent")

local TextBox = script.Parent

-- function you use whenever you want to send messages:
local function SendMessage()
	RemoteEvent:FireServer(TextBox.Text)
end

-- Calls SendMessage whenever you finish typing a message:
TextBox.FocusLost:Connect(SendMessage)

In a Script in the workspace:

script.Parent = game:GetService("ServerScriptService")

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Chat = game:GetService("Chat")

local RemoteEvent = ReplicatedStorage:FindFirstChild("MessageEvent") or Instance.new("RemoteEvent", ReplicatedStorage)
RemoteEvent.Name = "MessageEvent"

-- Function to call whenever a player sends text
local function RandSendText(player, text)
	if not player.Team then return end -- Quits the send request if the player is not on a team

	local teamPlayers = player.Team:GetPlayers() -- gets the players on the team of the player sending the message
	local randPlayer -- our variable to use for the random player we will send the message too

	repeat -- Sets the rand player to a player on the team who is not the sender of the message
		randPlayer = teamPlayers[math.random(#teamPlayers)
		wait(0.05)
	until (randPlayer ~= player)

	text = Chat:FilterStringAsync(text, player, randPlayer) -- Filters the string that is sent to the player. Do not remove this. Tags can be annoying, but they are required. Otherwise your game may be moderated and taken down.

	RemoteEvent:FireClient(randPlayer, text) -- Sends the text to a random player on the player who sent the message's team
end

-- Calls RandSendText whenever a player is sending a message to a random player on their team
RemoteEvent.OnServerEvent:Connect(RandSendEvent)


NOTE:
If you are the only player on your team the message will not be sent. Also, if you are not on a team and try to send a message then the message will not be sent.
The message will only be sent to a random player on your team if you are in a team.

When I saw A script in the workspace, I instantly got triggered lol

Seriously though, put server scripts in ServerScriptService. Even though you might just say It’s the same, it’s more organized and neat to put it in SSS. Workspace should have Models and 3D objects and camera stuff and such.
Also, FilterStringAsync only returns an Instance for you to extract text from. To get the filtered text, on the FSA object, call :GetNonChatStringForUserAsync(fireClientPlayer'sUserId)

I’m not being rude or something, the spoiler is just a joke. This is just to explain better use cases of scripts and correcting your mistakes.

First off, if you read my script the first thing it does is reparent itself to ServerScriptService | Roblox Creator Documentation. I know you should put scripts in ServerScriptService but because @jjadtru seems new to developing/scripting on Roblox I decided to keep things simple to prevent potential mistakes.

Also, TextService | Roblox Creator Documentation may not return a string, but Chat | Roblox Creator Documentation does.

Thank you for your response however, as informing others of mistakes makes them less ignorant of them and helps them learn from them.

EDIT: Lol. I managed to read what you said before you removed it.

1 Like

Well, the guy’s not dumb. I really think he could do such a simple thing as drag it to serverscriptservice.
But thanks for your reply

Yes, but if he doesn’t understand the function of ServerScriptService then he may think it is unnecessary to put the script in it or find it annoying to do as it might seem less accessible compared to what he normally does.

1 Like