Need help creating a killfeed

How can I remove the first template in my killfeed

killfeed cool.rbxl (27.7 KB)
please test in 2 player mode

I have tried doing this but no luck it just messes up the table

table.remove(KillTable, 1)

The code

local function adjust(clone)
	
	local absSizeY = clone.AbsoluteSize.Y
	local gapY = 10 
	local totalY = absSizeY + gapY
	
	for i,v in pairs(KillTable) do 
		clone.Name = "Gui"..i
		
		local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)
		local tween = tweenService:Create(v, tweenInfo, {Position =UDim2.new(0.9, 0, 0.05, (i-1)*totalY)})
		tween:Play()
	end

end

function contents:DisplayKill(player, Char, EnemyChar)
	local PlayerGui = player:WaitForChild("PlayerGui")
	local KillLogGui = PlayerGui:WaitForChild("KillLogGui")
	local Template = KillLogGui.Template 
	
	local Clone = Template:Clone()
	Clone.Parent = KillLogGui
	Clone.Name = "KilledGui"
	Clone.Visible = true
	
	local TextLabel = Clone.Frame.TextLabel 
	local textVar = Char.Name.." ".."Has".." "..killMessage[math.random(1, #killMessage)].." "..EnemyChar.Name
	TextLabel.Text = textVar
	
	table.insert(KillTable, Clone)
	adjust(Clone)
	
	
	
	
end

1 Like

When you remove an entry from the table, it will not automatically remove the UI element associated with it.

You can add a delay after parenting the UI to the frame, after which the frame/label is Destroy()ed and the entry is removed from the table.

4 Likes

I don’t understand somthing like this?

	if #KillTable >= 4 then 
		table.remove(KillTable, 1)
		KillTable[1]:Destroy()
		
		delay(3, function()
			
			
		end)
	end

No, something like this.

local function adjust(clone)
	
	local absSizeY = clone.AbsoluteSize.Y
	local gapY = 10 
	local totalY = absSizeY + gapY
	
	for i,v in pairs(KillTable) do 
		clone.Name = "Gui"..i
		
		local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)
		local tween = tweenService:Create(v, tweenInfo, {Position =UDim2.new(0.9, 0, 0.05, (i-1)*totalY)})
		tween:Play()
	end

end

function contents:DisplayKill(player, Char, EnemyChar)
	if #KillTable >= 4 then
		KillTable[1]:Destroy()
		table.remove(KillTable, 1) -- when you call table.remove it shifts all of the elements
		adjust(KillTable[1]) -- already iterates throygh everything
	end

	local PlayerGui = player:WaitForChild("PlayerGui")
	local KillLogGui = PlayerGui:WaitForChild("KillLogGui")
	local Template = KillLogGui.Template 
	
	local Clone = Template:Clone()
	Clone.Parent = KillLogGui
	Clone.Name = "KilledGui"
	Clone.Visible = true
	
	local TextLabel = Clone.Frame.TextLabel 
	local textVar = Char.Name.." ".."Has".." "..killMessage[math.random(1, #killMessage)].." "..EnemyChar.Name
	TextLabel.Text = textVar
	
	table.insert(KillTable, Clone)
	adjust(Clone)
end
2 Likes

for some reason when I do

table.remove(KillTable, 1)

it removes the 2nd gui instead of the firsrt

I think it’s because when you destroy it, it destroys the references to it, including the table.

3 Likes