I’m trying to make a billboard gui to show if a player is VIP. However, this only works half of the time. Here’s my script:
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local nametag = ReplicatedStorage.VIPNametag
Players.PlayerAdded:Connect(function(plr)
local hasVIP = false
local success, message = pcall(function()
hasVIP = MarketplaceService:UserOwnsGamePassAsync(plr.UserId, 95142223)
end)
if not success then
print("Error checking VIP:"..message)
elseif hasVIP then
plr:SetAttribute("IsVIP", hasVIP)
print(plr:GetAttribute("IsVIP"))
local char = plr.Character
if not char then
char = plr.CharacterAdded:Wait()
end
print("Char found")
local head = char:FindFirstChild("Head")
print("head found")
local hum = char:WaitForChild("Humanoid")
local newTag = nametag:Clone()
print("tag cloned")
newTag.Parent = head
newTag.Adornee = head
newTag.TextLabel.Text = "[VIP] "..plr.Name.." [VIP]"
print("label set")
hum.NameDisplayDistance = 0
end
end)
What I mean, is that half of the time, it won’t show the gui. How do I fix this?
Maybe try waiting for the characters appearance to fully load before running the code… Appearance loaded is better than character added just to let you know,
your issue probably was to do with waiting on the character way too lately.
Example
Code
local players = game:GetService("Players")
local marketplaceService = game:GetService("MarketplaceService")
local replicatedStorage = game:GetService("ReplicatedStorage")
players.PlayerAdded:Connect(function(player)
player.CharacterAppearanceLoaded:Connect(function(character)
local humanoid = character:FindFirstChild("Humanoid")
local boolean = false
--
local success, message = pcall(function()
boolean = marketplaceService:UserOwnsGamePassAsync(player.UserId, 95142223)
end)
--
if not success then -- error
print("Error checking VIP: "..message)
elseif boolean then -- if player owns gamepass
print(boolean)
local head = character:FindFirstChild("Head")
local tag = replicatedStorage.VIPNametag:Clone()
tag.Parent = head
tag.Adornee = head
tag.TextLabel.Text = "[VIP] "..player.Name.." [VIP]"
humanoid.NameDisplayDistance = 0
else -- player doesn't own the gamepass
print(boolean)
end
end)
end)
Cleaned your code a bit, and also if worked then mark as the solution. Thank you and bye for now.