So I am working on an Overhead GUI that appears over your head (obviously), but the text is not working to display the user’s info (Name, Display Name, Leaderstats). I also want it to make it so that when the leaderstat is at value 0, the color of the text will display as red.
Here is the code.
local nameText = script.Parent.NameText
local displayNameText = script.Parent.DisplayName
local timeLeftText = script.Parent.TimeLeft
game.Players.PlayerAdded:Connect(function(plr)
nameText.Text = "@"..plr.Name
displayNameText.Text = plr.DisplayName
local leaderstats = plr:WaitForChild("leaderstats"):WaitForChild("Time")
timeLeftText.Text = "Time Left: "..leaderstats.Value
if leaderstats.Value <= 0 then
timeLeftText.TextColor3 = Color3.fromRGB(255, 0, 0)
end
end)
The player joining and the character is being added just after the player joined so the script waiting the player joining. Try this :
local nameText = script.Parent.NameText
local displayNameText = script.Parent.DisplayName
local timeLeftText = script.Parent.TimeLeft
local char = script.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
script.Parent.Parent = char:WaitForChild("Head")
while wait() do
nameText.Text = "@"..plr.Name
displayNameText.Text = plr.DisplayName
local leaderstats = plr:WaitForChild("leaderstats"):WaitForChild("Time")
timeLeftText.Text = "Time Left: "..leaderstats.Value
if leaderstats.Value <= 0 then
timeLeftText.TextColor3 = Color3.fromRGB(255, 0, 0)
end
end