Nametag dissapearing after death

I’ve created a Nametag system for my game, however the nametag dissapears after the character has died.
From what I can find on other Forums I needed a “CharacterAdded”, I have one but it is not working, please help!
image

please, please add indentation!!! it would be very helpful if you did

have you tried making a script and placing it under StarterCharacterScripts?

-- placed in StarterCharacterScripts
local gamepassId = -- insert ID here
local marketServ = game:GetService("MarketplaceService")
local player = game.Players:GetPlayerFromCharacter(script.Parent)
local nametag = script.Nametag

if marketServ:UserOwnsGamePasssAsync(player.UserId, gamepassId) then
 nametag:Clone.Parent = player.Character.Head
end
1 Like

1st of all
don’t call market:UserOwnsGamePassAsync(plr.UserId, gamepassid) everytime plr respawns (it’s a tad bit slow)
edit: nvm it’s cached. still, i suggest you don’t call it repeatedly

2nd of all, add indendation. This doesn’t improve the script performance wise, but it makes it easier to read. (and also prevent triggering people’s OCD lol)

anyways

here’s what i’d do

-- a server **Script**, place in ServerScriptService. Place your nametag in the script and make sure it's actually called "Nametag".
local gamepassid = 231829122
local market = game:GetService("MarketplaceService")
local players = game:GetService("Players") -- yes, "Players" is a service. It's better to use :GetService(service) for reasons i won't get into
local nametag = script:WaitForChild("Nametag")
nametag.Adornee = nil -- I assume Nametag is a BillboardGui.

local function giveNametag(char)
    local head = char:WaitForChild("Head") -- :WaitForChild, in case the character loading is slow.
    local new = nametag:Clone()
    new.Adornee = head -- again, I'm making the bold assumption that "Nametag" is a BillboardGui here.
    new.Parent = head
end
local function onPlayer(player: Player) -- the ": Player" is just so script editor intellisense works
    if market:UserOwnsGamePassAsync(plr.UserId, gamepassid) then
        player.CharacterAdded:Connect(giveNametag)
        if player.Character then task.spawn(giveNametag, player.Character) end -- This is in case the player already spawned. I use task.spawn so the script doesn't wait for giveNametag to finish before continuing. also the rest of the code won't die if this errors.
    end
    -- if you want, you can add extra code here
end

players.PlayerAdded:Connect(onPlayer)
for _, player in ipairs(players:GetPlayers()) do
    task.spawn(onPlayer, player) -- this is done in case there are already people in game. Again, i use task.spawn for the same reason i use task.spawn for giveNametag.
end

oh yea btw if you find any errors (red text) when you press F9 when playtesting, try sending images of them. It helps a ton.

If you’re wondering what gamepassid is, here’s an image to help you understand
the numbers i underlined is the gamepassid
i’m pretty sure the gamepass should be on sale. or the script won’t work

1 Like

Got the script working fine, no errors. And you guessed correctly with the naming and properties of everything!

Couple issues though:

  • It still dissapears after my character dies
  • It only shows the nametag in Studio, actual Roblox Player…nothing [no errors]

There’s an error around the area of cloning of the character to my head, it just stays on the floor.

1 Like

replace the nametag:Clone.Parent in his script with nametag:Clone().Parent
maybe that’ll work

1 Like

:+1:that seems to have done it for that bit
now I’m recieving a new error

UserOwnsGamePasssAsync
you added an extra “s”, look a little closer

1 Like

Good catch, thank you. All working

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.