game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local nameGui = Instance.new("BillboardGui")
nameGui.StudsOffset = Vector3.new(0, 2, 0)
nameGui.Size = UDim2.new(0, 200, 0, 50)
nameGui.Name = "NameGui"
nameGui.Parent = char.Head
local nameLabel = Instance.new("TextLabel")
nameLabel.Text = plr.Name
nameLabel.TextScaled = true
nameLabel.Size = UDim2.new(0, 200, 0, 50)
nameLabel.BackgroundTransparency = 1
nameLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
nameLabel.Font = "Cartoon"
nameLabel.TextStrokeTransparency = 0
nameLabel.Name = "NameLabel"
nameLabel.Parent = nameGui
local INVENT_ID = 225233347 -- problem starts here
local player = game:GetService("Players").LocalPlayer
if player.UserId == INVENT_ID then
nameLabel.TextColor3 = Color3.fromRGB(255, 0, 0)
end
end)
end)
You wrote your code as game.Players.PlayerAdded:Connect(function(plr) then referenced plr as player.
1 Like
You can’t use Players.LocalPlayer in a Server Script. It is equal to nil.
Instead, I think you can do it like this:
Change this…
local player = game:GetService("Players").LocalPlayer
if player.UserId == INVENT_ID then
nameLabel.TextColor3 = Color3.fromRGB(255, 0, 0)
end
To this…
if plr.UserId == INVENT_ID then
nameLabel.TextColor3 = Color3.fromRGB(255, 0, 0)
end
2 Likes
local players = game:GetService("Players")
local INVENT_ID = 225233347
players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local nameGui = Instance.new("BillboardGui")
nameGui.StudsOffset = Vector3.new(0, 2, 0)
nameGui.Size = UDim2.new(0, 200, 0, 50)
nameGui.Name = "NameGui"
nameGui.Parent = char.Head
local nameLabel = Instance.new("TextLabel")
nameLabel.Text = plr.Name
nameLabel.TextScaled = true
nameLabel.Size = UDim2.new(0, 200, 0, 50)
nameLabel.BackgroundTransparency = 1
nameLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
nameLabel.Font = "Cartoon"
nameLabel.TextStrokeTransparency = 0
nameLabel.Name = "NameLabel"
nameLabel.Parent = nameGui
if plr.UserId == INVENT_ID then
nameLabel.TextColor3 = Color3.fromRGB(255, 0, 0)
end
end)
end)
Just fixing the formatting & some other stuff. As the previous post stated “game.Players.LocalPlayer” isn’t defined in server scripts and will just return “nil”, you also already had the player instance defined inside the variable named “plr” with the PlayerAdded event so all you needed to do was reuse that.