i making a small tower defense game, so far i finished the enemies, now i have to work on a simple tower that shoots, i tried using touched and touchended but it was very bad and laggy,
here is the old code:
local enemies = {}
local current = nil
local deb = true
while wait(0.5) do
script.Parent.Touched:Connect(function(x)
if x.Parent:FindFirstChild("Config") then
if table.find(enemies, x.Parent) == nil then
if deb == true then
deb = false
print(x.Parent.Name)
table.insert(enemies, x.Parent)
current = enemies[1]
wait(1)
deb = true
end
end
end
script.Parent.TouchEnded:Connect(function(x)
table.remove(enemies, 1, x.Parent)
current = nil
end)
if current ~= nil then
print(current.Config.Health.Value)
current.Config.Health.Value -= 2
print(current.Config.Health.Value)
wait(1)
end
end)
end
how would i make a tower that actually is not laggy and works?