Need help with overhead gui displaying a leaderboard stat value

Replace game.ServerStorage.BillBoardGui with game.ServerStorage:WaitForChild('BillboardGui') maybe?

1 Like

In ā€˜Game Settingsā€™ go to security and enable API Services.

In TimeScript where is ā€˜characterā€™ defined?

I think so


local player = game.Players:GetPlayerFromCharacter(character)

local leaderstats = player.leaderstats
local timeAlive = leaderstats["Time Alive"]
local bestTime = leaderstats["Best Time"]

local regionPart = workspace.Region

local min = regionPart.Position - (0.5 * regionPart.Size)
local max = regionPart.Position + (0.5 * regionPart.Size)
local region = Region3.new(min, max)

local function CheckSpawnRegion()
	local objects = workspace:FindPartsInRegion3WithWhiteList(region, {character})

	if #objects > 0 then
		if not character:FindFirstChildOfClass("ForceField") then
			local forceField = Instance.new("ForceField")
			forceField.Visible = true
			forceField.Parent = character
		end

		return true
	else
		local forceField = character:FindFirstChildOfClass("ForceField")

		if forceField then
			forceField:Destroy()
		end

		return false
	end
end

local hasDied = false

humanoid.Died:Connect(function()
	hasDied = true
end)

while wait() do
	if hasDied then break end

	while not hasDied and not CheckSpawnRegion() do
		timeAlive.Value += 1

		if timeAlive.Value > bestTime.Value then
			bestTime.Value = timeAlive.Value
		end

		wait(1)
	end

	if hasDied then
		timeAlive.Value = 0
	end
end

You forgot to define the character at the 1st line.

It cutted out

local humanoid = character.Humanoid

local player = game.Players:GetPlayerFromCharacter(character)

local leaderstats = player.leaderstats
local timeAlive = leaderstats["Time Alive"]
local bestTime = leaderstats["Best Time"]

local regionPart = workspace.Region

local min = regionPart.Position - (0.5 * regionPart.Size)
local max = regionPart.Position + (0.5 * regionPart.Size)
local region = Region3.new(min, max)

local function CheckSpawnRegion()
	local objects = workspace:FindPartsInRegion3WithWhiteList(region, {character})

	if #objects > 0 then
		if not character:FindFirstChildOfClass("ForceField") then
			local forceField = Instance.new("ForceField")
			forceField.Visible = true
			forceField.Parent = character
		end

		return true
	else
		local forceField = character:FindFirstChildOfClass("ForceField")

		if forceField then
			forceField:Destroy()
		end

		return false
	end
end

local hasDied = false

humanoid.Died:Connect(function()
	hasDied = true
end)

while wait() do
	if hasDied then break end

	while not hasDied and not CheckSpawnRegion() do
		timeAlive.Value += 1

		if timeAlive.Value > bestTime.Value then
			bestTime.Value = timeAlive.Value
		end

		wait(1)
	end

	if hasDied then
		timeAlive.Value = 0
	end
end

Maybe try this?

local character = script.Parent 
local player = game.Players:GetPlayerFromCharacter(character)

local humanoid = character:WaitForChild('Humanoid')

local leaderstats = player.leaderstats
local timeAlive = leaderstats["Time Alive"]
local bestTime = leaderstats["Best Time"]

local regionPart = workspace.Region

local min = regionPart.Position - (0.5 * regionPart.Size)
local max = regionPart.Position + (0.5 * regionPart.Size)
local region = Region3.new(min, max)

local function CheckSpawnRegion()
	local objects = workspace:FindPartsInRegion3WithWhiteList(region, {character})

	if #objects > 0 then
		if not character:FindFirstChildOfClass("ForceField") then
			local forceField = Instance.new("ForceField")
			forceField.Visible = true
			forceField.Parent = character
		end

		return true
	else
		local forceField = character:FindFirstChildOfClass("ForceField")

		if forceField then
			forceField:Destroy()
		end

		return false
	end
end

local hasDied = false

humanoid.Died:Connect(function()
	hasDied = true
end)

while wait() do
	if hasDied then break end

	while not hasDied and not CheckSpawnRegion() do
		timeAlive.Value += 1

		if timeAlive.Value > bestTime.Value then
			bestTime.Value = timeAlive.Value
		end

		wait(1)
	end

	if hasDied then
		timeAlive.Value = 0
	end
end
1 Like

After you try it, show us the output again.

image

Yes, The only problem now it seems is

I see that theres and error at the top, can you show us what it is?

1 Like

Can you show us the full output?

image

It works

Change it to

local leaderstats = player:WaitForChild("leaderstats")

Put TimeScript inside StarterCharacterScripts and put this inside the nametag script:

local Players = game:GetService('Players')
local BillboardGui = game.ServerStorage:WaitForChild('BillboardGui')

Players.PlayerAdded:Connect(function(Player)
    local leaderstats = Player:WaitForChild('leaderstats')
	local timeAlive = leaderstats:WaitForChild('Time Alive')
	
	Player.CharacterAdded:Connect(function(Character)
		local BillboardClone = BillboardGui:Clone()
		BillboardClone.Parent = Character:WaitForChild("Head")
		BillboardClone.TextLabel.Text = timeAlive.Value

		timeAlive:GetPropertyChangedSignal('Value'):Connect(function()
			BillboardClone.TextLabel.Text = timeAlive.Value
		end)
	end)
end)

You enabled access to API Services and then applied and saved it, right?

Can you take a NEW picture of the output so we can see everything that is currently erroring?

IT WORKS! THANK YOU!!!

1 Like