I’ve managed to make a Height Bar GUI to visualize how far a player is up a set of stairs, I’ve looked everywhere and couldn’t find how to add all players in the server on the bar. If anyone has experience, help would be much appreciated!
HeightScript:
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local PlayerGui = Player:FindFirstChild("PlayerGui")
if Player:FindFirstChild("PlayerGui") then
while wait() do
local ImageLabel = PlayerGui.HeightGui.Frame:FindFirstChild("ImageLabel")
local Character = game:GetService("Workspace")[Player.Name]
local PrimaryPart = Character:FindFirstChild("HumanoidRootPart")
local Height = math.ceil(PrimaryPart.Position.Y)
local totalrange = -765.125
local percent = Height / totalrange
ImageLabel.Position = UDim2.new(-0.25, 0, percent + 1, 0)
end
end
Image Script:
local ThumbnailType = Enum.ThumbnailType.HeadShot
local ThumbnailSize = Enum.ThumbnailSize.Size48x48
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
while wait() do
script.Parent.Image = Players:GetUserThumbnailAsync(Player.userId, ThumbnailType, ThumbnailSize)
end
In Game:
(note: bottom of bar huminodrootpart position y is “0” and top of the bar is “765.125”)
You should only have one script, and you should not be setting the player’s image in a while wait() loop. You also shouldn’t be using while wait() to update the player’s position on the frame. A way to add all players is by using a loop.
Replace both LocalScripts with one (that is under Frame and not under ImageLabel) that has this pasted inside:
--//Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
--//Variables
local LocalPlayer = Players.LocalPlayer
local Frame = script.Parent
local ImageLabel = script.ImageLabel
--//Controls
local ThumbnailType = Enum.ThumbnailType.HeadShot
local ThumbnailSize = Enum.ThumbnailSize.Size48x48
--//Functions
local function OnPlayerAdded(player)
local newImage = ImageLabel:Clone()
newImage.Name = player.UserId
newImage.Image = Players:GetUserThumbnailAsync(player.UserId, ThumbnailType, ThumbnailSize)
newImage.Parent = Frame
local HumanoidRootPart = nil
player.CharacterAdded:Connect(function(character)
HumanoidRootPart = character:WaitForChild("HumanoidRootPart", 5)
local updateConnection = nil
updateConnection = RunService.Heartbeat:Connect(function()
if not HumanoidRootPart then
updateConnection:Disconnect()
return
end
local currentHeight = math.ceil(HumanoidRootPart.Position.Y)
local highestPoint = -765.125
local percent = currentHeight / highestPoint
ImageLabel.Position = UDim2.fromScale(-0.25, percent + 1)
end)
end)
player.CharacterRemoving:Connect(function()
HumanoidRootPart = nil
end)
end
local function OnPlayerRemoving(player)
local currentImage = Frame:FindFirstChild(player.UserId)
if currentImage then
currentImage:Destroy()
end
end
Players.PlayerAdded:Connect(OnPlayerAdded)
Players.PlayerRemoving:Connect(OnPlayerRemoving)
for i, player in ipairs(Players:GetPlayers()) do
task.spawn(OnPlayerAdded, player)
end
Thanks for the quick reply! after replacing the new script with the old and adjusting the layout. It seems to only update the image, Not the actual position of the image. Maybe I made a mistake on my end that I didn’t see?
I forgot to account for if the player’s character already exists. Your current setup looks right.
Code:
--//Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
--//Variables
local LocalPlayer = Players.LocalPlayer
local Frame = script.Parent
local ImageLabel = script.ImageLabel
--//Controls
local ThumbnailType = Enum.ThumbnailType.HeadShot
local ThumbnailSize = Enum.ThumbnailSize.Size48x48
--//Functions
local function OnPlayerAdded(player)
local newImage = ImageLabel:Clone()
newImage.Name = player.UserId
newImage.Image = Players:GetUserThumbnailAsync(player.UserId, ThumbnailType, ThumbnailSize)
newImage.Parent = Frame
local HumanoidRootPart = nil
local function OnCharacterAdded(character)
HumanoidRootPart = character:WaitForChild("HumanoidRootPart", 5)
local updateConnection = nil
updateConnection = RunService.Heartbeat:Connect(function()
if not HumanoidRootPart then
updateConnection:Disconnect()
return
end
local currentHeight = math.ceil(HumanoidRootPart.Position.Y)
local highestPoint = -765.125
local percent = currentHeight / highestPoint
ImageLabel.Position = UDim2.fromScale(-0.25, percent + 1)
end)
end
player.CharacterAdded:Connect(OnCharacterAdded)
player.CharacterRemoving:Connect(function()
HumanoidRootPart = nil
end)
if player.Character then
OnCharacterAdded(player.Character)
end
end
local function OnPlayerRemoving(player)
local currentImage = Frame:FindFirstChild(player.UserId)
if currentImage then
currentImage:Destroy()
end
end
Players.PlayerAdded:Connect(OnPlayerAdded)
Players.PlayerRemoving:Connect(OnPlayerRemoving)
for i, player in ipairs(Players:GetPlayers()) do
task.spawn(OnPlayerAdded, player)
end
--//Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
--//Variables
local LocalPlayer = Players.LocalPlayer
local Frame = script.Parent
local ImageLabel = script.ImageLabel
--//Controls
local ThumbnailType = Enum.ThumbnailType.HeadShot
local ThumbnailSize = Enum.ThumbnailSize.Size48x48
--//Functions
local function OnPlayerAdded(player)
local newImage = ImageLabel:Clone()
newImage.Name = player.UserId
newImage.Image = Players:GetUserThumbnailAsync(player.UserId, ThumbnailType, ThumbnailSize)
newImage.Parent = Frame
local Character = player.Character or player.CharacterAdded:Wait()
local HumanoidRootPart = nil
local function OnCharacterAdded(character)
HumanoidRootPart = character:WaitForChild("HumanoidRootPart", 5)
local updateConnection = nil
updateConnection = RunService.Heartbeat:Connect(function()
if not HumanoidRootPart then
updateConnection:Disconnect()
return
end
local currentHeight = math.ceil(HumanoidRootPart.Position.Y)
local highestPoint = -765.125
local percent = currentHeight / highestPoint
ImageLabel.Position = UDim2.fromScale(-0.25, percent + 1)
end)
end
player.CharacterAdded:Connect(OnCharacterAdded)
player.CharacterRemoving:Connect(function()
HumanoidRootPart = nil
end)
OnCharacterAdded(Character)
end
local function OnPlayerRemoving(player)
local currentImage = Frame:FindFirstChild(player.UserId)
if currentImage then
currentImage:Destroy()
end
end
Players.PlayerAdded:Connect(OnPlayerAdded)
Players.PlayerRemoving:Connect(OnPlayerRemoving)
for i, player in ipairs(Players:GetPlayers()) do
task.spawn(OnPlayerAdded, player)
end
Very weird, still not working. Based on the beginner-intermediate coding knowledge I have, the code you provided looks like it should work. I really don’t know why it doesn’t???
Made 2 prints at the start and end of the OnCharacterAdded function
--//Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
--//Variables
local LocalPlayer = Players.LocalPlayer
local Frame = script.Parent
local ImageLabel = script.ImageLabel
--//Controls
local ThumbnailType = Enum.ThumbnailType.HeadShot
local ThumbnailSize = Enum.ThumbnailSize.Size48x48
--//Functions
local function OnPlayerAdded(player)
print("before")
local newImage = ImageLabel:Clone()
newImage.Name = player.UserId
newImage.Image = Players:GetUserThumbnailAsync(player.UserId, ThumbnailType, ThumbnailSize)
newImage.Parent = Frame
local Character = player.Character or player.CharacterAdded:Wait()
local HumanoidRootPart = nil
local function OnCharacterAdded(character)
HumanoidRootPart = character:WaitForChild("HumanoidRootPart", 5)
local updateConnection = nil
updateConnection = RunService.Heartbeat:Connect(function()
if not HumanoidRootPart then
updateConnection:Disconnect()
return
end
local currentHeight = math.ceil(HumanoidRootPart.Position.Y)
local highestPoint = -765.125
local percent = currentHeight / highestPoint
ImageLabel.Position = UDim2.fromScale(-0.25, percent + 1)
end)
print("after")
end
player.CharacterAdded:Connect(OnCharacterAdded)
player.CharacterRemoving:Connect(function()
HumanoidRootPart = nil
end)
OnCharacterAdded(Character)
end
local function OnPlayerRemoving(player)
local currentImage = Frame:FindFirstChild(player.UserId)
if currentImage then
currentImage:Destroy()
end
end
Players.PlayerAdded:Connect(OnPlayerAdded)
Players.PlayerRemoving:Connect(OnPlayerRemoving)
for i, player in ipairs(Players:GetPlayers()) do
task.spawn(OnPlayerAdded, player)
end
Seemed to both print:
Thanks for the help you’ve been providing me I really appreciated it!
Would it be possible to add you to a place with the gui in it so we don’t have to keep going back and forth? If not I don’t mind doing what you say but just would take a bit longer