Is it possible to make when I press a button everything I wrote in my text label will be shown to a random person in a team? for example if I write kill the red player I would like that text to go to a random person on the blue team
You can pretty much make anything you want, so yes.
so how can i do it can you help me please
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
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)
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
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.