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

Server Scripts reset on death?

Hi! I've recently created a VIP Gamepass for my server, and the player get's a VIP nametag over his head using billboard guis. However, whenever the player dies, the tag disappears, how do I fix this?

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:connect(function(char)
        if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(game.Players[char.Name].UserId, id) then
		char.Humanoid.NameDisplayDistance = 60
			local clonedgui = billboardgui:Clone()
			clonedgui.Parent = game.Workspace[player.Name].Head
			clonedgui.TextLabel.Text = "VIP"
			clonedgui.TextVip.Text = player.Name
			
			while true do
			char.Humanoid.JumpPower = 60
			wait()
			end
        end
    end)
end)

1 answer

I recommend putting the script into StarterPlayerScripts and get rid of these functions. This will execute anytime the player respawns.

--[[ Not needed. - game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:connect(function(char)]]

local Character = script.Parent.Name -- gets their name
local UserId = game.Players.UserId -- gets their id, not needed if you have a variable to do this already

if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(UserId, id) then
	char.Humanoid.NameDisplayDistance = 60
	local clonedgui = billboardgui:Clone()
        clonedgui.Parent = game.Workspace[player.Name].Head
        clonedgui.TextLabel.Text = "VIP"
        clonedgui.TextVip.Text = player.Name
 
        while true do
            	char.Humanoid.JumpPower = 60
              	wait()
         end
end
--[[    end)
-- Not needed. - end)]]

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