BillboardGui isn’t a TextLabel, also using Instance.new with the parent is bad practice, see this.
Besides, you cannot access the LocalPlayer from the server-side.
You should instead use the PlayerAdded event that is in the Players service.
Your current script would also only check it once, so if a player reached 1000 points they’d have to rejoin.
Why are you defining leaderstatsScript when you are not using it anywhere?
Another problem I see is that you’re trying to get the leaderstats value, which wouldn’t be actually shown on the Roblox leaderboard.
You probably meant to reference points instead of leaderstats.
Also, the humanoid isn’t a part of the player, rather the player’s character.
I’m not sure if BillboardGui would show if it was parented to a humanoid.
Your fixed code would probably look more like this:
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local MVP_MIN_POINTS = 1000
local function CreateMVPBillboard(Parent)
local BillboardGui = Instance.new("BillboardGui")
BillboardGui.Name = "MVP BillboardGui"
BillboardGui.Adornee = Parent
BillboardGui.LightInfluence = 0
BillboardGui.Size = UDim2.new(4, 0, 4, 0)
BillboardGui.StudsOffsetWorldSpace = Vector3.new(0, 4, 0)
BillboardGui.ZIndexBehavior = Enum.ZIndexBehavior.Global
local TextLabel = Instance.new("TextLabel")
TextLabel.BackgroundTransparency = 1
TextLabel.Name = "MVP Label"
TextLabel.Text = "MVP"
TextLabel.TextColor3 = Color3.fromRGB(255, 50, 50)
TextLabel.Size = UDim2.new(0.8, 0, 0.8, 0)
-- helps to distinct text in any environment
TextLabel.TextStrokeTransparency = 0
TextLabel.TextScaled = true
TextLabel.Parent = BillboardGui
BillboardGui.Parent = Parent
return BillboardGui
end
local function PlayerAdded(Player)
local leaderstats = Player:WaitForChild("leaderstats")
local Points = leaderstats:WaitForChild("Points")
Player.CharacterAdded:Connect(function(Character)
repeat RunService.Heartbeat:Wait() until workspace:IsAncestorOf(Character)
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
if not HumanoidRootPart then
return
end
if not Humanoid then
return
end
local BillboardGui
if MVP_MIN_POINTS <= Points.Value then
BillboardGui = CreateMVPBillboard(HumanoidRootPart)
end
local c
c = Points:GetPropertyChangedSignal("Value"):Connect(function()
if MVP_MIN_POINTS > Points.Value then
if BillboardGui then
BillboardGui:Destroy()
BillboardGui = nil
end
elseif MVP_MIN_POINTS <= Points.Value then
if not BillboardGui then
BillboardGui = CreateMVPBillboard(HumanoidRootPart)
end
end
end)
-- I don't need to disconnect the died connection, due to the fact that
-- the connection gets erased once the Humanoid is destroyed,
-- which is probably a few seconds after .Died is fired.
Humanoid.Died:Connect(function()
c:Disconnect()
if BillboardGui then
BillboardGui:Destroy()
BillboardGui = nil
end
end)
end)
end
Players.PlayerAdded:Connect(PlayerAdded)
This should be in a server script.