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.
Thanks, I have tried that now but I am getting an error I have never seen before.
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)
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.
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)
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)
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).