Nametag cloning for everyone

I am trying to script a nametag system that gets a players rank from a group and name and put it on the players head.

It works fine for one person but when another person joins, everyone in the server gets their nametag.

Something like this:

But the other person can also get the nametag as well.

Here is the script: (server script in StarterCharacterScripts

local character = script.Parent
local riflesTag = script:FindFirstChild("Rifles")
local civillianTag = script:FindFirstChild("Civillian")

local groupID = 13016143

local playerRank = game.Players:GetPlayerFromCharacter(character):GetRoleInGroup(groupID) 


local rs = game:GetService("ReplicatedStorage")

local cvCheckFL = rs.TitlesRES:WaitForChild("cvCheckFL")
local cvCheckFS = rs.TitlesRES:WaitForChild("cvCheckFS")

local rfCheckFL = rs.TitlesRES:WaitForChild("cvCheckFL")
local rfCheckFS = rs.TitlesRES:WaitForChild("cvCheckFS")



local re = rs:WaitForChild("titleGiver")
local rfChecker = rs:WaitForChild("rifChecker")


local allowed = rs.TitlesRES:WaitForChild("allowed")
local errormsg = rs.TitlesRES:WaitForChild("errormessage")

--bools

local function cvChecker(player, character, ntClone)
	character = character or player.Character or player.CharacterAdded:Wait() -- // Making sure the character really exists.
	if player:GetRankInGroup(13016143) >= 0 then
		print("civillian")
		ntClone = civillianTag:Clone()
		wait(.1)
		ntClone.Parent = character:FindFirstChild("Head")
		ntClone.Adornee = character:FindFirstChild("Head")
		ntClone.playerName.Text = character.Name
		ntClone.playerRank.Text = "<font color='#FF7276'> [Civillian], </font> "..playerRank 
		ntClone.Enabled = true
		wait(0.3)
	end	
end

local function rifChecker(player, character, rfClone)
	character = character or player.Character or player.CharacterAdded:Wait()
	if player:GetRankInGroup(13016143) > 1 then
		print("rifles")
		rfClone = riflesTag:Clone()
		wait(.1)
		rfClone.Parent = character:FindFirstChild("Head")
		rfClone.Adornee = character:FindFirstChild("Head")
		rfClone.playerName.Text = character.Name
		rfClone.playerRank.Text = "<font color='#146606'> [RIFLES], </font> " ..playerRank
		rfClone.Enabled = true
		wait(0.3)
	end
end

local function checker(player, character)
	character = character or player.Character or player.CharacterAdded:Wait()
	if player:GetRankInGroup(13016143) == 1 or player:GetRankInGroup(13016143) == 0 then
		print("not allowed")
		errormsg:FireClient(player)
	end	
end

local function rfCheck(player, character)
	character = character or player.Character or player.CharacterAdded:Wait()
	if player:GetRankInGroup(13016143) > 1 then
		rfCheckFS:FireClient(player)
	end
end



--13016097 rf instruct.

re.OnServerEvent:Connect(cvChecker)	
rfChecker.OnServerEvent:Connect(rifChecker)	
rfCheckFL.OnServerEvent:Connect(rfCheck)
allowed.OnServerEvent:Connect(checker)

I am not really sure why this is happening.

Show the script which fires these remotes.

(local script)

print("Server Version - 12")

--services
local rs = game:GetService("ReplicatedStorage")
local ts  = game:GetService("TweenService")

--remote events
local rfChecker = rs:WaitForChild("rifChecker")
local cvChecker = rs:WaitForChild("titleGiver")

local allowed = rs.TitlesRES:WaitForChild("allowed")
local errormsg = rs.TitlesRES:WaitForChild("errormessage")

local cvCheckFL = rs.TitlesRES:WaitForChild("cvCheckFL")
local cvCheckFS = rs.TitlesRES:WaitForChild("cvCheckFS")

local rfCheckFL = rs.TitlesRES:WaitForChild("cvCheckFL")
local rfCheckFS = rs.TitlesRES:WaitForChild("cvCheckFS")

--buttons/text/frames
local tsFrame = script.Parent
local cvFrame = tsFrame.cvFrame
local rfFrame = tsFrame.rfFrame

local cvSelect = cvFrame.cvSelect
local rfSelect = rfFrame.rfSelect

local errorTxt = tsFrame.errorMsg

local playBtn = script.Parent.Parent.optionsFrame.playBtn

local tsTwOut = ts:Create(tsFrame, TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Position = UDim2.new(-1,0,0,0)})
local tsTwIn = ts:Create(tsFrame, TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Position = UDim2.new(0,0,0,0)})

local errorFadein = ts:Create(errorTxt, TweenInfo.new(0.3 , Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {TextTransparency = 0})
local errorFadeout = ts:Create(errorTxt, TweenInfo.new(2 , Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {TextTransparency = 1})

cvSelect.MouseButton1Click:Connect(function()
	tsTwOut:Play()
	cvChecker:FireServer()
	print("CV FIRED")
end)

rfSelect.MouseButton1Click:Connect(function()
	rfChecker:FireServer()
	allowed:FireServer()
	print("RF FIRED")
	rfCheckFL:FireServer()
end)

local function errortxtFade()
	print("error")
	errorFadein:Play()
	wait(2)
	errorFadeout:Play()	
end

local function rfRecieve()
	tsTwOut:Play()
end

errormsg.OnClientEvent:Connect(errortxtFade)
rfCheckFS.OnClientEvent:Connect(rfRecieve)

Sorry for the messy script lol

See, this script is in starterchsracter

So EVERYONE has a script inside to make a nametag

The event is in replicatedstorage

EVERYONES script is activated when you fire the events from your local script because they are ALL listening for same event

1 Like

Perhaps have one serverscriptservice server script to make the nametags

So how would I go about fixing this? Would I use a server script in ServerScriptService to make the nametag, and then put it on the players head in the script in Starter Character?

The remoteevent passes the player too so just as normal have a bit in the server script parenting the nametag to player.Character.Head

I dont know what your context is so idk if you always want the nametag but i dont even use a local script

I just listen for the playeradded event of players then listen to the characteradded for that player then clone a nametag into the characters head

1 Like