Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to add Team Mark GUI over player?

I am trying to add a team marker over the player's head so that the players in the game may recognize their teammates. I have two different GUI's and my goal is that a player could only see their teammates GUI. I wrote this script it seems to be working fine. But I have noticed sometimes some few players are missing the marker even if they are on the same team.

Here is the local script

local Players = game:GetService("Players")
local LocalPlayer = game:GetService("Players").LocalPlayer
local LocalPlayerTeam = LocalPlayer.Team.Name
local PinkTeambbg = game.ReplicatedStorage:WaitForChild("PinkTeamMark")
local BlueTeambbg = game.ReplicatedStorage:WaitForChild("BlueTeamMark")
local PinkTeamGui = PinkTeambbg:Clone()
local BlueTeamGui = BlueTeambbg:Clone()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEventTest = ReplicatedStorage:WaitForChild("RemoteEventTest")

local function AddMark(player)		--Checks the color of team and adds the mark

	if LocalPlayerTeam == "Pink" then

		PinkTeamGui.Parent = game.Workspace:WaitForChild(player.Name):WaitForChild("Head")
	else

		BlueTeamGui.Parent = game.Workspace:WaitForChild(player.Name):WaitForChild("Head")
	end
end

remoteEventTest.OnClientEvent:Connect(function()
	for _, player in pairs(Players:GetPlayers()) do	--Iterate through all the players 
		if player.Team.Name == LocalPlayerTeam  then	--And check if the player is in same team with local player
			AddMark(player)					--If in same Team Add Mark
		end	
	end
end)

I'm firing the remoteEventTest under player.CharacterAdded.

1 comment

0

Are the players who don’t have the marker over their head players that have joined the game during the match (if you can)

1 answer

Let's real fast have a quick look at line 6 and 7. You wrote the following snippet of code:

local PinkTeamGui = PinkTeambbg:Clone()
local BlueTeamGui = BlueTeambbg:Clone()

Why does this matter? Well let's assume that two players are on each team. The script indexes through all the Pink team players first. You wrote in that section (inside the mark function) this:

if LocalPlayerTeam == "Pink" then

        PinkTeamGui.Parent = game.Workspace:WaitForChild(player.Name):WaitForChild("Head")
else

You might be wondering why this matters. The answer is that there is only one tag that can be used. The script gets the tag and parents it to the Player1's head. Then Player2, who is also on pink team, takes the tag from Player1.

To fix this, add the make a clone every time a tag is being assigned. Like so:

if LocalPlayerTeam == "Pink" then
	local PinkTeamGui = PinkTeambbg:Clone()
        PinkTeamGui.Parent = game.Workspace:WaitForChild(player.Name):WaitForChild("Head")
else

Then simply do the same thing for the other teams. Hope this helped!

This discussion is preserved as it was. New answers, comments, and votes are closed.