Need help with making an TD styled Health List UI

Hey, i want to make an Health list UI inspired by the now deleted Sonic.exe: The Disaster for my Game “Sonic.exe: Your own Blood”, but i need help of making this cuz i’m not the greatest roblox scripter (I mostly look at Tutorials but there’s still other things that i need to learn). Can anyone help me do this?

Here’s a screenshot from a video while the game was still up:

You can do it by using UIListLayout.
For example, you can make a frame of a container containing UIListLayout and clone the player’s ui into the container every time a player is added.

2 Likes

tbh, how do i use it? Just asking (Sorry if that sounded rude)

I can’t test it now, so it’s not accurate, but you can use it like this

-- local script

local players = game:GetService("Players")

local gui = script.Parent
local container = gui.ContainerFrame -- put UIListLayout inside it
local playerFrame = script.PlayerFrame

local function CreateFrames()
	for _, v in pairs(players:GetPlayers())
		local clonedFrame = playerFrame:Clone()
		clonedFrame.Parent = container
		clonedFrame.TextLabel.Text = v.Name -- Synchronize each player's name to TextLabel
		…
	end
end

CreateFrames()
1 Like

K, thx for the answer.

So… got the script to work. But i firstly made an custom health system (So i could add the TD Minion system) without other players first, but i couldn’t get another feature to work (A bone break feature). It’ll be for another post just to not make this discussion confusing:
So… this is the health “localscript” called “LocalHealth” it the Health GUI:

local Label = script.Parent
local health = 100
local hitbox = game.Workspace.Hitbox
local Players = game:GetService("Players")
local touched = false
local hitsound = game.ReplicatedStorage["X hit"]
local Replicated = game:GetService("ReplicatedStorage")
local UserInput = game:GetService("UserInputService")

local Player = Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(character)
local BoneSound = game.ReplicatedStorage.BoneBreaking


	Label.Text = "health: " .. health
	
hitbox.Touched:Connect(function(hit)
	if player then
		if touched == false then
			if health > 0 then
				hitsound:Play()
				health = health - 10
				if health == 50 then
					BoneSound:Play()
				end
			end
			touched = true
			Label.Text = "health: " .. health
		end
	end
end)	

hitbox.TouchEnded:Connect(function(hit)
	if player then
		if touched == true then
			wait(1)
			touched = false
		end
	end
end)	

My question is how i should actually show the health of the other players. Can you help me with this? Just asking

I rewrote previous function.

-- local script

local players = game:GetService("Players")

local gui = script.Parent
local container = gui.ContainerFrame -- put UIListLayout inside it
local playerFrame = script.PlayerFrame
local healthLabel = playerFrame.HealthLabel -- put it inside the PlayerFrame

local function CreateFrames()
	for _, v in pairs(players:GetPlayers())
		local clonedFrame = playerFrame:Clone()
		clonedFrame.Parent = container
		clonedFrame.TextLabel.Text = v.Name
		…
		--new code
		local char = v.Character
		local hum = char:FindFirstChild("Humanoid")
		hum:GetPropertChangedSignal("Health"):Connect(function()
			--your function here
		end)
	end
end

CreateFrames()

I think the reason why the bone sound doesn’t work is because it’s in ReplicatedStorage. If you clone BoneSound and make Parent workspace, it will be solved.

tbh, that actually wasn’t the problem, i would add a event to another local script, but it hadn’t worked, so i did it with the replicated storage thing

So… tried to make this script work and well…

-- local script

local players = game:GetService("Players")

local gui = script.Parent
local container = gui.ContainerFrame -- put UIListLayout inside it
local playerFrame = script.PlayerFrame
local healthLabel = playerFrame.HealthLabel -- put it inside the PlayerFrame
local Label = script.Parent
local health = 100
local hitbox = game.Workspace.Hitbox
local Players = game:GetService("Players")
local touched = false
local hitsound = game.ReplicatedStorage["X hit"]
local Replicated = game:GetService("ReplicatedStorage")
local UserInput = game:GetService("UserInputService")

local Player = Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(character)
local BoneSound = game.ReplicatedStorage.BoneBreaking

local function CreateFrames()
	for _, v in pairs(players:GetPlayers()) do
		local clonedFrame = playerFrame:Clone()
		clonedFrame.Parent = container
		clonedFrame.TextLabel.Text = v.Name
		Label.Text = "health: " .. health
		local char = v.Character
		local hum = char:FindFirstChild("Humanoid")
		hum:GetPropertChangedSignal("Health"):Connect(function()
			hitbox.Touched:Connect(function(hit)
				if player then
					if touched == false then
						if health > 0 then
							hitsound:Play()
							health = health - 10
							if health == 50 then
								BoneSound:Play()
							end
						end
						touched = true
						Label.Text = "health: " .. health
					end
				end
			end)	

			hitbox.TouchEnded:Connect(function(hit)
				if player then
					if touched == true then
						wait(1)
						touched = false
					end
				end
			end)	
		end)
end
end

CreateFrames()

It didn’t work as expected. So… here are the error codes, ig:

Script 'Players.Sonicu2022.PlayerGui.HealthGUI.LocalScript', Line 31 - function CreateFrames  -  Studio - LocalScript:31
  10:26:46.997  Script 'Players.Sonicu2022.PlayerGui.HealthGUI.LocalScript', Line 63  -  Studio - LocalScript:63

If that doesn’t really sound respectful, i’m sorry

Sorry i realized i made some typos in the old code… i fixed it.
Regarding the hitbox, it will work by putting a code in the hitbox.

local players = game:GetService("Players")

local gui = script.Parent -- screen gui
local container = gui.ContainerFrame -- frame
local playerFrame = script.PlayerFrame -- frame

local function CreateFrames()
	for _, v in pairs(players:GetPlayers()) do
		local char = v.Character
		local hum = char:FindFirstChildOfClass("Humanoid")
		
		local clonedFrame = playerFrame:Clone() -- clone of player frame
		local nameLabel = clonedFrame.NameLabel -- text label for name
		local healthLabel = clonedFrame.HealthLabel -- text label for health
		
		clonedFrame.Parent = container
		nameLabel.Text = "Name: " .. v.Name
		healthLabel.Text = "Health: " .. math.round(hum.Health) -- init health label
		
		hum:GetPropertyChangedSignal("Health"):Connect(function()
			healthLabel.Text = "Health: " .. math.round(hum.Health) -- update health label
		end)
	end
end
task.wait(1) -- wait for player to load
CreateFrames()
1 Like

So… tried to add everything that’s in it:


So… did i miss anything? Just asking

So… tried to add the frames and labels, but there’s still some errors. Strangely, it has sth to do with the “Create frames” thing.

 22:06:25.865  Script 'Players.Sonicu2022.PlayerGui.HealthGUI.LocalScript', Line 14 - function CreateFrames  -  Studio - LocalScript:14
  22:06:25.865  Script 'Players.Sonicu2022.PlayerGui.HealthGUI.LocalScript', Line 27  -  Studio - LocalScript:27

Looked if i could fix it, but i dunno how. Sorry if i annoyed, disturbed you or if i doesn’t sound respectful to you

Can you show me the code? There seems to be an additional code.

sure

local players = game:GetService("Players")

local gui = script.Parent -- screen gui
local container = gui.ContainerFrame -- frame
local playerFrame = script.PlayerFrame -- frame
local Health = 100

local function CreateFrames()
	for _, v in pairs(players:GetPlayers()) do
		local char = v.Character
		local hum = char:FindFirstChildOfClass("Humanoid")

		local clonedFrame = playerFrame:Clone() -- clone of player frame
		local nameLabel = clonedFrame.NameLabel -- text label for name
		local healthLabel = clonedFrame.HealthLabel -- text label for health

		clonedFrame.Parent = container
		nameLabel.Text = "Name: " .. v.Name
		healthLabel.Text = "Health: " .. math.round(Health) -- init health label

		hum:GetPropertyChangedSignal("Health"):Connect(function()
			healthLabel.Text = "Health: " .. math.round(Health) -- update health label
		end)
	end
end
task.wait(1) -- wait for player to load
CreateFrames()

I found it out, there were 2 things called “HealthLabel”

So… i think it’s solved now, thank you

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