Scripting a ground progress bar

Hi everyone, I have posted something similar to this before, but I did not get a clear answer.
What im trying to do is making a ground progress bar for an obby game.
Something like this;


Now, i am not trying to make a bar like in tower of hell, I need it to be horizontal, not vertical.
If someone could please help, it would be greatly appreciated. I am not that good at scripting.

I would go at making a client render step function that loops through all required characters in the race, get the magnitude between the character’s HumanoidRootPart position and the goal position, then for each magnitude, divide it by the magnitude from the start position to the goal position, and use that for the X scale position for the characters head on the frames.

Sorry, as I said im not a good scripter. Can you make a simple script for this? Thanks.

Just chipping in, but these two objects:

local targetPosition = game.Workspace.End
local startPosition = game.Workspace.Arrow

Are they models, or parts? If they’re models, you’re going to need to assign it a PrimaryPart and set that variable to something like this.

local targetPosition = game.Workspace.End:GetPrimaryPartCFrame().Position
local startPosition = game.Workspace.Arrow:GetPrimaryPartCFrame().Position

If they’re parts, you can just get their CFrame/Position property like so:

local targetPosition = game.Workspace.End.CFrame.Position
local startPosition = game.Workspace.Arrow.CFrame.Position
2 Likes

Thanks, I have tried that now but I am getting an error I have never seen before.
image

	local targetPosition = game.Workspace.End.CFrame.Position
	local startPosition = game.Workspace.Arrow.CFrame.Position
	local totalDist = (targetPosition - startPosition).Magnitude
	local players = game.Players:GetPlayers() -- Assuming all connected players are being calculated
	for _,player in pairs(players) do
		local char = player.Character
		local humanoidRootPart = char:FindFirstChild("HumanoidRootPart")
		if humanoidRootPart then
			local dist = (targetPosition - humanoidRootPart.Position).Magnitude
			local playerImage = game.Players:GetUserThumbnailAsync(player.UserId, Enum.ThumbnailSize.Size420x420, Enum.ThumbnailType.HeadShot)
			local PlayerImage2 = game.StarterGui.Bar.Frame.PlayerImage.Image
			local perc = 1 - (totalDist - dist)
			PlayerImage2.Position = UDim2.fromScale(perc, 0)
		end
	end
end)

what line is that error occuring?

You got the parameters the wrong way around, the second argument should be the thumbnail type, the last one should be the thumbnail size.

Huh? (Sorry if it seems easy to fix, i am very bad at scripting)
image

You put ‘players.UserId’ as the first argument, but players isn’t a thing, which is why you’re being shown ‘Argument 1 missing or nil’ because it’s nil.

Just change players to player. :slight_smile:


image

	local EndPosition = game.Workspace.End.CFrame.Position
	local startPosition = game.Workspace.Arrow.CFrame.Position
	local totalDist = (EndPosition	 - startPosition).Magnitude
	local players = game.Players:GetPlayers()
	
	-- Assuming all connected players are being calculated
	for _,player in pairs(players) do
		local char = player.Character
		local humanoidRootPart = char:FindFirstChild("HumanoidRootPart")
		if humanoidRootPart then
			local dist = (EndPosition - humanoidRootPart.Position).Magnitude
			local playerImage = game.Players:GetUserThumbnailAsync(player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
			local perc = 1 - (totalDist - dist)
			playerImage.Image.Position = UDim2.fromScale(perc, 0)
		end
	end
end)

attempt to index nil means that you tried calling something that didn’t exist:
try this instead

playerImage.Position = UDim2.fromScale(perc, 0)

Tried this already but same error happens

Show us what the bar frame looks like. I imagine you have a script that automatically generated all of the player images when the race started?

No… I thought the playerImage was used for that purpose.

Make a new image label and set the image to be playerimage then use that image label to set the position.

It’s because :GetUserThumbnailAsync() (playerImage in this case) returns a tuple. You’re gonna want to create a new variable to assign this to, and below that, create a new instance of ImageLabel, set the image equal to the content it returns. An example of how this would look is this:

local EndPosition = game.Workspace.End.CFrame.Position
local startPosition = game.Workspace.Arrow.CFrame.Position
local totalDist = (EndPosition	 - startPosition).Magnitude
local players = game.Players:GetPlayers()

-- Assuming all connected players are being calculated
for _,player in pairs(players) do
	local char = player.Character
	local humanoidRootPart = char:FindFirstChild("HumanoidRootPart")
	
	if humanoidRootPart then
		local dist = (EndPosition - humanoidRootPart.Position).Magnitude
		local playerImageContent, isReadyToBeUsed = game.Players:GetUserThumbnailAsync(player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
		
		local playerImage = Instance.new("ImageLabel")
		playerImage.Image = playerImageContent
		playerImage.Parent = LOCATION_OF_IMAGES
		
		local perc = 1 - (totalDist - dist)
		playerImage.Position = UDim2.fromScale(perc, 0)
	end
end
end)
2 Likes

image

Ah, then if you already have an ImageLabel made, then just assign that to the new playerImage variable that I made instead (rather than creating a new ImageLabel instance, but you might want to do this if you are getting players on your game dynamically, creating a new instance of the image for every player).

local playerImage = script.Parent.PlayerImage
1 Like