Progress Bar Tower Of Hell

The script works all fine, but the frame that is copied every frame isn’t visible on the screen, even tho its .Visible is set to true. Maybe because it’s getting destroyed too fast??

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local maxDistance = game.Workspace.Distance.Size.Z
local minDistance = 0

RunService.RenderStepped:Connect(function()
	local currentPlayers = Players:GetPlayers()
	
	for i, child in pairs(script.Parent:GetChildren()) do
		if child:IsA("Frame") then child:Destroy() end
	end
	
	for _, player in currentPlayers do
		local blankFrame = script.Parent.Folder.Frame
		local newFrame = blankFrame:Clone()
		
		newFrame.Parent = script.Parent
		newFrame.Name = player.Name
		newFrame.Image.ImageLabel.Image = Players:GetUserThumbnailAsync(player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
		newFrame.Visible = true
		
		local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
		
		local plrDistance = math.clamp(humanoidRootPart.Position.Z, minDistance, maxDistance)
		local guiDistance = (plrDistance * 500) / maxDistance
		
		
		newFrame.Position = UDim2.new(0, guiDistance, 0, 0)
	end
end)

To be fair using Players:GetUserThumbnailAsync() has quite a delay on loading. But I dont see why you are destroying the frame? How I see it, you are deleting the frame, remaking it and then moving it.

2 Likes

how would I do it without destroying it??

Make a single frame for each player in a table and find it in the render stepped. If there is no frame, then make it there. Also check the table in each render stepped aswell, to check and weed out frames from players that left.

how would that look in terms of code? I cant get it to work… Thanks!

Here’s how you can do it! :heart:

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local maxDistance = game.Workspace.Distance.Size.Z
local minDistance = 0

local frames = {}  -- Table to store player frames

RunService.RenderStepped:Connect(function()
	local currentPlayers = Players:GetPlayers()

	for _, player in ipairs(currentPlayers) do
		local playerName = player.Name
		local blankFrame = script.Parent.Folder.Frame
		local newFrame = frames[playerName]

		if not newFrame then
			newFrame = blankFrame:Clone()
			newFrame.Name = playerName
			newFrame.Parent = script.Parent
			newFrame.Visible = true
			frames[playerName] = newFrame
		end

		newFrame.Image.ImageLabel.Image = Players:GetUserThumbnailAsync(player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)

		local humanoidRootPart = player.Character and player.Character:FindFirstChild("HumanoidRootPart")
		if humanoidRootPart then
			local plrDistance = math.clamp(humanoidRootPart.Position.Z, minDistance, maxDistance)
			local guiDistance = (plrDistance * 500) / maxDistance
			newFrame.Position = UDim2.new(0, guiDistance, 0, 0)
		end
	end

	-- Remove frames for players who left the game
	for playerName, frame in pairs(frames) do
		if not Players:FindFirstChild(playerName) then
			frame:Destroy()
			frames[playerName] = nil
		end
	end
end)

Fixed it! :happy2:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.