You can write your topic however you want, but you need to answer these questions: 1. What do you want to achieve? Keep it simple and clear!
I want to make a bar height so it shows up the journey of the player while htey are climbing up.
What is the issue? Include screenshots / videos if possible!
Well, i made a script which references the HumanoidRootpart position (Y) into a local variable yHeight and it works perfectly… The issue comes after the player dies, it seems that the height bar clones himself at the top of the bar and also showing the error message “Infinite yield possible on 'Workspace.Edigamer_Roblox2:WaitForChild(“HumanoidRootPart”)” which i dont understand whats happening.
local bar = script.Parent
local heightTemplate = script:WaitForChild("PlayerHeight")
local goingUp = false
local maxHeight = workspace.HeightPart.Position.Y
local minHeight = 0
local heightDifference = maxHeight - minHeight
local increments = 1 / heightDifference
game:GetService("RunService").RenderStepped:Connect(function()
for i, plr in pairs(game.Players:GetPlayers()) do
local heightIndicator = heightTemplate:Clone()
local plrImage = game.Players:GetUserThumbnailAsync(plr.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
heightIndicator.PlayerImage.Image = plrImage
heightIndicator.Parent = bar
local char = plr.Character or plr.CharacterAdded:Wait()
local yHeight = math.clamp(char:WaitForChild("HumanoidRootPart").Position.Y, minHeight, maxHeight)
local yPos
if goingUp then
yPos = yHeight * increments
else
yPos = (maxHeight - yHeight) * increments
end
heightIndicator.Position = UDim2.new(heightIndicator.Position.X.Scale, heightIndicator.Position.X.Offset, yPos, 0)
wait()
heightIndicator:Destroy()
end
end)
What solutions have you tried so far?
So basically i was trying to look if character was the problem and other things but i am still in the same thing.
local bar = script.Parent
local heightTemplate = script:WaitForChild("PlayerHeight")
local goingUp = false
local maxHeight = workspace.HeightPart.Position.Y
local minHeight = 0
local heightDifference = maxHeight - minHeight
local increments = 1 / heightDifference
game:GetService("RunService").RenderStepped:Connect(function()
for i, plr in pairs(game.Players:GetPlayers()) do
local heightIndicator = heightTemplate:Clone()
local plrImage = game.Players:GetUserThumbnailAsync(plr.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
heightIndicator.PlayerImage.Image = plrImage
heightIndicator.Parent = bar
local char = plr.Character or plr.CharacterAdded:Wait()
local yHeight = math.clamp(char:WaitForChild("HumanoidRootPart", 10).Position.Y, minHeight, maxHeight)
local yPos
if goingUp then
yPos = yHeight * increments
else
yPos = (maxHeight - yHeight) * increments
end
heightIndicator.Position = UDim2.new(heightIndicator.Position.X.Scale, heightIndicator.Position.X.Offset, yPos, 0)
wait()
heightIndicator:Destroy()
end
end)
local bar = script.Parent
local heightTemplate = script:WaitForChild("PlayerHeight")
local goingUp = false
local maxHeight = workspace.HeightPart.Position.Y
local minHeight = 0
local heightDifference = maxHeight - minHeight
local increments = 1 / heightDifference
game:GetService("RunService").RenderStepped:Connect(function()
for i, plr in pairs(game.Players:GetPlayers()) do
if plr.Character.Humanoid.Health ~= 0 then
local heightIndicator = heightTemplate:Clone()
local plrImage = game.Players:GetUserThumbnailAsync(plr.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
heightIndicator.PlayerImage.Image = plrImage
heightIndicator.Parent = bar
local char = plr.Character or plr.CharacterAdded:Wait()
local yHeight = math.clamp(char:WaitForChild("HumanoidRootPart").Position.Y, minHeight, maxHeight)
local yPos
if goingUp then
yPos = yHeight * increments
else
yPos = (maxHeight - yHeight) * increments
end
heightIndicator.Position = UDim2.new(heightIndicator.Position.X.Scale, heightIndicator.Position.X.Offset, yPos, 0)
wait()
heightIndicator:Destroy()
end
end
end)
You should probably also add a check for the HumanoidRootPart.
... -first half of the script
local HumanoidRootPart = Char:FindFirstChild("HumanoidRootPart")
if not HumanoidRootPart then return end
... -rest of the script
Try this solution script, if it works the character root part has not name as HumanoidRootPart but another:
local bar = script.Parent
local heightTemplate = script:WaitForChild("PlayerHeight")
local goingUp = false
local maxHeight = workspace.HeightPart.Position.Y
local minHeight = 0
local heightDifference = maxHeight - minHeight
local increments = 1 / heightDifference
game:GetService("RunService").RenderStepped:Connect(function()
for i, plr in pairs(game.Players:GetPlayers()) do
local heightIndicator = heightTemplate:Clone()
local plrImage = game.Players:GetUserThumbnailAsync(plr.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
heightIndicator.PlayerImage.Image = plrImage
heightIndicator.Parent = bar
local char = plr.Character or plr.CharacterAdded:Wait()
local hrp = plr:FindFirstChildOfClass("Humanoid").RootPart
local yHeight = math.clamp(hrp.Position.Y, minHeight, maxHeight)
local yPos
if goingUp then
yPos = yHeight * increments
else
yPos = (maxHeight - yHeight) * increments
end
heightIndicator.Position = UDim2.new(heightIndicator.Position.X.Scale, heightIndicator.Position.X.Offset, yPos, 0)
wait()
heightIndicator:Destroy()
end
end)
I just tested it right now and the output showed more errors about indexing nil with the position of HRPart after i corrected the line where you put:
local hrp = plr:FindFirstChildOfClass("Humanoid").RootPart
because is indexing with nil and also i dont think using FindFirstChildOfClass would be a best way to earn the hrp and writting .RootPart after the “Humanoid” sentence.
In short words is not working.
local bar = script.Parent
local heightTemplate = script:WaitForChild("PlayerHeight")
local goingUp = false
local maxHeight = workspace.HeightPart.Position.Y
local minHeight = 0
local heightDifference = maxHeight - minHeight
local increments = 1 / heightDifference
local lastTime = DateTime.now()
local countdown = 100
game:GetService("RunService").RenderStepped:Connect(function()
repeat wait() until DateTime.now().UnixTimestampMillis-lastTime>countdown --Countdown System
lastTime = DateTime.now()
for i, plr in pairs(game.Players:GetPlayers()) do
local heightIndicator = heightTemplate:Clone()
local plrImage = game.Players:GetUserThumbnailAsync(plr.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
heightIndicator.PlayerImage.Image = plrImage
heightIndicator.Parent = bar
local char = plr.Character or plr.CharacterAdded:Wait()
local hrp = char:FindFirstChild("HumanoidRootPart")
if not hrp then continue end
local yHeight = math.clamp(hrp.Position.Y, minHeight, maxHeight)
local yPos
if goingUp then
yPos = yHeight * increments
else
yPos = (maxHeight - yHeight) * increments
end
heightIndicator.Position = UDim2.new(heightIndicator.Position.X.Scale, heightIndicator.Position.X.Offset, yPos, 0)
wait()
heightIndicator:Destroy()
end
end)