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

This is how ‘In-Experience Text Chat | Roblox Creator Documentation’, although it does require a bit of scripting knowledge.

ok thank you ill check it out
:smile: :grinning:

ok i read it but it does not seem to help me with what i want

From what I understand you want GUI to be present that gives instructions to a team?
Depending on what you write in a textbox?

yes that is what I would like but the instructions should go to one random person in the team

This is accomplishable with the Player | Roblox Creator Documentation property. You will also need to understand how to use a RemoteEvent | Roblox Creator Documentation.
You must pass the information through the server first though, as stated on RemoteEvent | Roblox Creator Documentation,

“Sometimes a game will need to send information from one client to another. Roblox does not support direct client to client contact, so any communication must first go through the server. This is typically done using remote events (although functions could be used if desired). First, the sending client would call FireServer. On the server, the function connected to OnServerEvent would hear this firing, and itself would then call FireClient.”

Also, we must use Chat | Roblox Creator Documentation because we are privately sending a message between two players.

You can do something like this in a local script:

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

local MessageLabel = ExampleVariablePath -- You will want to define this as the TextLabel you want to have the message appear in

-- Use this whenever you want to send the info to a random player on your team
RemoteEvent:FireServer(TextBox.Text)

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

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

	MessageLabel.Visible = false
end

Then, on a server script:

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

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

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

	RemoteEvent:FireClient(randPlayer, text)
end

RemoteEvent.OnServerEvent:Connect(RandSendEvent)

**Note:**I assume that you already have the textbox pre-defined, indicated by my use of a TextBox variable.

Also, it’s a good thing that we have to send the string through the server because it allows us to filter it securely. In other words: Never trust the client.

i want it so like when the player is done writing the text in the textbox and thy press submit it sends to a random player on a team

script in your button

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Button = script.Parent
local Text = script.Parent.Parent.TextLabelNameHere
local function GetRandomTeam()
      local Teams1 = #game:GetService("Teams"):GetTeams() -- Number of teams
      local RandomTeamIndex = math.random(1, Teams1) -- Random team between 1 and number of teams
      local RandomTeam = game:GetService("Teams"):GetTeams()[RandomTeamIndex] -- random team
      return RandomTeam -- return it
end
local function GetRandomPlayer(Team)
        local Player1 = #Team:GetPlayers()
        local RandomTeamIndex = math.random(1, Player1)
        return Team:GetPlayers()[RandomTeamIndex] or nil
end
Button.Activated:Connect(function()
       local Team = GetRandomTeam()
       local RandomTeamPlayer = GetRandomPlayer(Team)
       if RandomTeamPlayer then
              local EnteredText = Text.Text
              local TeamName = Team.Name
              -- do something with the text and team
       end
end)
1 Like

so where should i put the team name???

I only answered how to get a random team and player from it. In your code, you should fire a remote event with the Player, Message (filtered) and Team, then on the server update the Player’s Gui with a new TextLabel containing the message inside his PlayerGui.
(I will make a repro place file later)

but i dont want it to be a random team

Oh. Then just replace the “Team” variable with game.Teams.YourTeamName

where i see a billion teams in it

Check my response up above. I edited it so it’s complete.

ok ima check it out :smile: :grinning: :smiley:

so will this make it when a player press submit all of there text from the textbox will go to them but as a textlabel

Isn’t that what you want? If you just sent them a message in a text box then they could edit it and delete it before they finished reading it. With a TextLabel | Roblox Creator Documentation they can’t edit it and are only able to read it. Also, I’m assuming you already have a ScreenGui | Roblox Creator Documentation and it’s UI Elements set up already in a local script.

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: