Hello guys, i have made a system where you open a GUI it loads all the players from the player list, whenver u click on them they get an invite button to join your “team”, whenever you accept a random team generates and players that are within that team will get BillboardGUI, however i dont know how to make it so other people wont see theyre overhead gui’s, since i’ve already used PlayerToHideFrom for the player so it wont be annoying that you would see your team tag.
script for enabling and if not in player team then disabling the gui CLIENT
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BillboardEvent = ReplicatedStorage:WaitForChild("BillboardEvent")
local Players = game:GetService("Players")
-- Handle incoming visibility updates
BillboardEvent.OnClientEvent:Connect(function(action, otherPlayer)
if action == "ShowBillboard" then
-- Get the local player and the target player
local localPlayer = Players.LocalPlayer
local character = localPlayer.Character
if character then
-- Find the BillboardGui
local billboard = character:FindFirstChild("GroupBillboardGui_" .. otherPlayer.Name)
if billboard then
-- Check if the local player and the other player are in the same team
if localPlayer.Team == otherPlayer.Team then
-- If in the same team, show the BillboardGui
billboard.Enabled = true
else
-- If not in the same team, hide the BillboardGui
billboard.Enabled = false
end
end
end
end
end)
and this script handles the accept button,billboard,teams creation SERVER
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Teams = game:GetService("Teams")
-- RemoteEvent to handle group requests and responses
local InviteEvent = ReplicatedStorage:WaitForChild("InviteEvent")
local BillboardEvent = ReplicatedStorage:WaitForChild("BillboardEvent")
-- Function to create and attach the BillboardGui
local function AddBillboardToPlayer(player, otherPlayer)
-- Clone the BillboardGui from ServerStorage
local billboard = ServerStorage:WaitForChild("PlayerTAG"):Clone()
billboard.Name = "GroupBillboardGui_" .. otherPlayer.Name
billboard.Adornee = player.Character:WaitForChild("Head") -- Attach to the player's head
billboard.Enabled = true
billboard.Parent = player.Character -- Parent it to the character
billboard.PlayerToHideFrom = player
-- Update the text or display
local textLabel = billboard:FindFirstChild("player_name") -- Adjust this to match your GUI design
if textLabel then
textLabel.Text = otherPlayer.Name
end
end
-- Function to handle accepting a group request and assigning to a random team
local function HandleGroupAcceptance(sender, targetPlayer)
if not sender.Character or not targetPlayer.Character then return end
-- Check if sender already has a team, if not create a new one
local teamName = "Team_" .. sender.UserId -- Unique team for each player based on their UserId
local team = Teams:FindFirstChild(teamName)
-- If the team doesn't exist, create it
if not team then
team = Instance.new("Team")
team.Name = teamName
team.TeamColor = BrickColor.Random() -- Assign a random team color
team.Parent = Teams -- Add the team to the Teams service
end
-- Assign both players to the same team
sender.Team = team
targetPlayer.Team = team
-- Add BillboardGui to both players
AddBillboardToPlayer(sender, targetPlayer)
AddBillboardToPlayer(targetPlayer, sender)
-- Ensure the BillboardGui is only visible to the two players
BillboardEvent:FireClient(sender, "ShowBillboard", targetPlayer)
BillboardEvent:FireClient(targetPlayer, "ShowBillboard", sender)
end
-- Listen for invites and acceptances
InviteEvent.OnServerEvent:Connect(function(sender, action, targetPlayerName)
local targetPlayer = Players:FindFirstChild(targetPlayerName)
if action == "Accept" and targetPlayer then
HandleGroupAcceptance(sender, targetPlayer)
end
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BillboardEvent = ReplicatedStorage:WaitForChild("BillboardEvent")
local Players = game:GetService("Players")
BillboardEvent.OnClientEvent:Connect(function(action, otherPlayer)
local localPlayer = Players.LocalPlayer
if not localPlayer or not localPlayer.Character then return end
local billboard = localPlayer.Character:FindFirstChild("GroupBillboardGui_" .. otherPlayer.Name)
if not billboard then return end
if action == "ShowBillboard" then
if localPlayer.Team == otherPlayer.Team then
billboard.Enabled = true
else
billboard.Enabled = false
end
elseif action == "HideBillboard" then
billboard.Enabled = false
end
end)
local function UpdateBillboardVisibility(player, targetPlayer)
for _, otherPlayer in pairs(Players:GetPlayers()) do
if otherPlayer ~= player and otherPlayer ~= targetPlayer then
if otherPlayer.Team ~= player.Team then
BillboardEvent:FireClient(otherPlayer, "HideBillboard", targetPlayer)
end
end
end
end
local function HandleGroupAcceptance(sender, targetPlayer)
if not sender.Character or not targetPlayer.Character then return end
local teamName = "Team_" .. sender.UserId
local team = Teams:FindFirstChild(teamName)
if not team then
team = Instance.new("Team")
team.Name = teamName
team.TeamColor = BrickColor.Random()
team.Parent = Teams
end
sender.Team = team
targetPlayer.Team = team
AddBillboardToPlayer(sender, targetPlayer)
AddBillboardToPlayer(targetPlayer, sender)
BillboardEvent:FireClient(sender, "ShowBillboard", targetPlayer)
BillboardEvent:FireClient(targetPlayer, "ShowBillboard", sender)
UpdateBillboardVisibility(sender, targetPlayer)
UpdateBillboardVisibility(targetPlayer, sender)
end
Hello sadly still the same happens however now even you can see your own tag, i might be dumb or have done something wrong. Down below ill pin how i imported ur updated script
LocalScript:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BillboardEvent = ReplicatedStorage:WaitForChild("BillboardEvent")
local Players = game:GetService("Players")
BillboardEvent.OnClientEvent:Connect(function(action, otherPlayer)
local localPlayer = Players.LocalPlayer
if not localPlayer or not localPlayer.Character then return end
local billboard = localPlayer.Character:FindFirstChild("GroupBillboardGui_" .. otherPlayer.Name)
if not billboard then return end
if action == "ShowBillboard" then
if localPlayer.Team == otherPlayer.Team then
billboard.Enabled = true
else
billboard.Enabled = false
end
elseif action == "HideBillboard" then
billboard.Enabled = false
end
end)
ServerScript:
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Teams = game:GetService("Teams")
-- RemoteEvent to handle group requests and responses
local InviteEvent = ReplicatedStorage:WaitForChild("InviteEvent")
local BillboardEvent = ReplicatedStorage:WaitForChild("BillboardEvent")
-- Function to create and attach the BillboardGui
local function AddBillboardToPlayer(player, otherPlayer)
-- Clone the BillboardGui from ServerStorage
local billboard = ServerStorage:WaitForChild("PlayerTAG"):Clone()
billboard.Name = "GroupBillboardGui_" .. otherPlayer.Name
billboard.Adornee = player.Character:WaitForChild("Head") -- Attach to the player's head
billboard.Enabled = true
billboard.Parent = player.Character -- Parent it to the character
-- Update the text or display
local textLabel = billboard:FindFirstChild("player_name") -- Adjust this to match your GUI design
if textLabel then
textLabel.Text = otherPlayer.Name
end
-- Add logic for `PlayerToHideFrom` if supported in your game setup
billboard.PlayerToHideFrom = nil -- Clear any pre-set value
end
local function UpdateBillboardVisibility(player, targetPlayer)
for _, otherPlayer in pairs(Players:GetPlayers()) do
if otherPlayer ~= player and otherPlayer ~= targetPlayer then
if otherPlayer.Team ~= player.Team then
BillboardEvent:FireClient(otherPlayer, "HideBillboard", targetPlayer)
end
end
end
end
local function HandleGroupAcceptance(sender, targetPlayer)
if not sender.Character or not targetPlayer.Character then return end
local teamName = "Team_" .. sender.UserId
local team = Teams:FindFirstChild(teamName)
if not team then
team = Instance.new("Team")
team.Name = teamName
team.TeamColor = BrickColor.Random()
team.Parent = Teams
end
sender.Team = team
targetPlayer.Team = team
AddBillboardToPlayer(sender, targetPlayer)
AddBillboardToPlayer(targetPlayer, sender)
BillboardEvent:FireClient(sender, "ShowBillboard", targetPlayer)
BillboardEvent:FireClient(targetPlayer, "ShowBillboard", sender)
UpdateBillboardVisibility(sender, targetPlayer)
UpdateBillboardVisibility(targetPlayer, sender)
end
-- Listen for invites and acceptances
InviteEvent.OnServerEvent:Connect(function(sender, action, targetPlayerName)
local targetPlayer = Players:FindFirstChild(targetPlayerName)
if action == "Accept" and targetPlayer then
HandleGroupAcceptance(sender, targetPlayer)
end
end)
I have attached a new script below, this script basically toggles all other BillboardGui’s for the client, this hides the client player’s BillboardGui.
local player = game:GetService("Players").LocalPlayer
local event = game:GetService("ReplicatedStorage").BillBoardEvent
event.OnClientEvent:Connect(function(action, otherPlayers)
local setValue = false
if action == "ShowBillboard" then
setValue = true
else
setValue = false
end
for _,v in pairs(game.Players:GetPlayers()) do
if v.Character then
if v.Character:FindFirstChild(`GroupBillboardGui_{v.Name}`) then
v.Character[`GroupBillboardGui_{v.Name}`].Enabled = setValue
end
end
end
end)
For team checking, you can easily add your own functions!