To make a trigger that alerts players when someone of a certain team enters a building, make a script with the following steps:
Touched event in invisible part spanning length and width of door or gateway.
Check the player’s team, if police then fire a remoteevent to all clients.
Upon picking the remote event up on the client, use StarterGui:SetCore(action) to create a notification for the player. The method you’ll want is called SendNotification.
Fill out parameters and done! :0
Would make this neater and more clear but on phone and just cba.
Important: You must always perform SetCore actions on the client or else they won’t work!!
You would want to create a part, add a remote into replicatedstorage, and create a touched function. You’re also going to need to insert stringvalues inside of the players. And you will also need a LocalScript to create the function that runs when this script fires.
local brick = script.Parent
local notification = game.ReplicatedStorage:WaitForChild("NotifierEvent")
function scanForCriminal(Player, Area)
for _,criminal in pairs(game.Players:GetPlayers()) do
local PlayersLocation = criminal:FindFirstChild("Area")
if PlayersLocation.Value ~= Area then
else
if criminal:FindFirstChild("Role") and criminal.Role.Value == "Criminal" then
notification:FireClient(Player, criminal)
end
end
end
end
brick.Touched:Connect(function(Hit)
if game.Players:GetPlayerFromCharacter(Hit.Parent) then
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Player:FindFirstChild("Role") and Player.Role.Value == "Cop" then
local BrickArea = script.Parent.Name
if Player:FindFirstChild("Area") then
local PlayersLocation = Player:FindFirstChild("Area")
if PlayersLocation.Value ~= BrickArea then
PlayersLocation.Value = BrickArea
scanForCriminal(Player, BrickArea)
end
end
end
end
end)
The script above uses ‘FireClient’ with the arguments Player, and criminal. In your local script you can create an event that detects when the specific player’s client has been called.
You simply make a variable locating the remote event, and use ‘OnClientEvent’ as an event to connect the function. After that you just need to add the criminal argument inside of that function because since your script is local you can get the player either way.
e.g
local Remote = game.ReplicatedStorage:WaitForChild("NotifierEvent")
local Player = game.Players.LocalPlayer
Remote.OnClientEvent:Connect(function(criminal)
-- do stuff here
end)
You can change the script above the part that says ‘FireClient(Player, criminal’ to ‘FireAllClients(criminal)’, if that’s what you meant.
No, FireAllClients() fires to each client in game.
Essentially, think of it as a pairs loop of all the players in the game and doing FireClient()
On the client, just reference the player as LocalPlayer as it doesn’t matter. Format your arguments you want to pass through such as the criminal’s name to display and the building they entered.
E.g.
-- Server
Event:FireAllClients(criminal, building)
-- Client
Event.OnClientEvent:Connect(function(player, criminal, building)