How to display a UI for a Team only

Hello, I’m trying to make a system of alert message which consists in sending a message via the Screen Gui Tablet and the message is displayed on the screen of the policemen thanks to the ScreenGui EmergencyCalls (like a notification).

I tried to make a Remote Event so that the “notification” is displayed for the players but when we send the message, all the players have the notification. I would like the notification ( EmergencyCalls Screen gui ) to be displayed only for the police, how to do that?

example of the problem in the picture (everyone gets the notification, not just the police)

the script in EmergencyCalls GUI:

local players = game:GetService("Players")
local player = players.LocalPlayer

game.ReplicatedStorage.Tablet.CallsEvent.OnServerEvent:Connect(function(player, text)
		print(text)
		script.Parent.Parent.Visible = true
		script.Parent.Text = text
		wait(10)
		script.Parent.Parent.Visible = false
end)

the LocalScript of TabletGui :

local players = game:GetService("Players")
local player = players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	local textbox = script.Parent.Parent.Text
	game.ReplicatedStorage.Tablet.CallsEvent:FireServer(textbox)
end)

3 Likes
— your function 
if player.Team == Police then
game.StarterGui.YourUi.Parent = player.PlayerGui
end

I’d suggest putting the UI in workspace or something so that when you join the game a player doesn’t see the UI since it’s in starterGUi

Change your LocalScript to this:

--//Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local CallsEvent = ReplicatedStorage.Tablet.CallsEvent
local TextButton = script.Parent
local TextBox = TextButton.Parent

--//Functions
TextButton.MouseButton1Click:Connect(function()
	CallsEvent:FireServer(TextBox.Text)
end)

And change your server script to this:

--//Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local CallsEvent = ReplicatedStorage.Tablet.CallsEvent
local TextLabel = script.Parent

--//Functions
CallsEvent.OnServerEvent:Connect(function(player, text)
	local LocalPlayer = TextLabel:FindFirstAncestorWhichIsA("Player")
	
	if not LocalPlayer or LocalPlayer.Team ~= player.Team then
		return
	end	

	TextLabel.Text = text
	TextLabel.Parent.Visible = true
	
	task.wait(10)
	TextLabel.Parent.Visible = false
end)
3 Likes

Your script generates no errors but still has a problem. If a citizen sends a message he receives the notification of the message (PoliceFrame) and all the other citizens too while it is supposed to be visible only for the policemen. But when a policeman sends a message he receives the notification and the others outside the police team receive nothing (that’s good for this point).

1 Like

Try changing:
LocalPlayer.Team ~= player.Team

To:
LocalPlayer.Team.Name ~= "Police"

3 Likes

Thank you so much it works ! love you

1 Like