wait(1)
startingheartx = 0.004
startinghearty = 0.011
Lighting = game.Lighting
hearts = {}
function NewHeart(httype)
local prevheart = nil
if httype == "Empty_Half" then
if #hearts == 0 then
local Heart = Lighting.Hearts.Empty_Half:Clone()
Heart.Name = "Empty_Half_1"
print(Heart.Name)
Heart.Parent = script.Parent
table.insert(hearts, 1, "Empty_Half")
else
if hearts[1] == "Empty_Half" then
local counter = tostring(#hearts)
local lastheart = script.Parent:FindFirstChild("Empty_Half_"..counter)
local lastposition = lastheart.Position
lastheart:Remove()
local Heart = Lighting.Hearts.Empty_Full:Clone()
Heart.Position = lastposition
Heart.Parent = script.Parent
hearts[#hearts] = "Empty_Full"
table.remove(hearts, 2)
else
local Heart = Lighting.Hearts.Empty_Half:Clone()
Heart.Position = UDim2.new(0.004 + (#hearts * 0.03), 0, 0.011, 0)
Heart.Name = Heart.Name.."_".. tostring(#hearts)
Heart.Parent = script.Parent
table.insert(hearts, 1, "Empty_Half")
end
end
end
end
function StartItUp()
local heartcount = 0
repeat
print("try "..heartcount)
NewHeart("Empty_Half")
heartcount = heartcount + 1
wait()
until heartcount == 6
end
StartItUp()
This is all the lonely 48 lines of code I have written for a different health system. It makes halves and converts two halves into a full, then moves other halves to the side. However, i get a little error that I’ve given up on fixing on “try 3”.
23:47:47.081 - Players.hboogy101.PlayerGui.ScreenGui.LocalScript:20: attempt to index local 'lastheart' (a nil value)
23:47:47.082 - Stack Begin
23:47:47.083 - Script 'Players.hboogy101.PlayerGui.ScreenGui.LocalScript', Line 20 - global NewHeart
23:47:47.084 - Script 'Players.hboogy101.PlayerGui.ScreenGui.LocalScript', Line 42 - global StartItUp
23:47:47.085 - Script 'Players.hboogy101.PlayerGui.ScreenGui.LocalScript', Line 48
23:47:47.085 - Stack End
I’m able to make one full heart and then a half, but then it gives me this error. Can any of you tell me how to fix my messy code?