Znimator
(znimator)
July 1, 2020, 4:49pm
#1
You can write your topic however you want, but you need to answer these questions:
I tried make hitboxes what can hit multiple targets but it works bad
anybody know how i can make hitbox hit multiple targets once/many times
local hitbox = {}
hitbox.attack = function(size,cframe,root,dmg,howlong,effect,CanSound,plr)
local targets = {}
local bb = 0
local ht = Instance.new("Part")
ht.Size = size
ht.Name = "Hitbox"
ht.CanCollide = false
ht.Transparency = 0.9
ht.Material = Enum.Material.SmoothPlastic
ht.Color = Color3.fromRGB(0,255,0)
local weld = Instance.new("Weld")
ht.CFrame = cframe
ht.Massless = true
weld.Part0 = ht
weld.Part1 = root
weld.C0 = ht.CFrame:Inverse()
weld.C1 = root.CFrame:Inverse()
ht.Parent = workspace
weld.Parent = ht
game.Debris:AddItem(ht,howlong)
ht.Touched:Connect(function(hit)
if hit and hit.Parent:FindFirstChild("Humanoid") ~= nil and hit.Parent.Name ~= plr.Name then
local item = table.find(targets,hit.Parent)
if item == nil then
bb = bb+1
table.insert(targets,bb,hit.Parent)
local enemy = hit.Parent.Humanoid
enemy:TakeDamage(dmg)
end
end
end)
end
return hitbox
2 Likes
astraIboy
(The Batman)
July 1, 2020, 4:51pm
#2
How about you just use a region three or get GetTouchingParts()
Znimator
(znimator)
July 1, 2020, 4:52pm
#3
can you bring me example? it would be cool
astraIboy
(The Batman)
July 1, 2020, 4:53pm
#4
Well just search up region three or gettouchingparts() in the search and youll find some good information
2sgo
(2sgo)
July 1, 2020, 5:09pm
#5
You could put every target that was hit into a table and check if they were in the list
local alreadyHit = {}
function addHit(target)
if not alreadyHit[target.Name] then --checks if target is in the table
alreadyHit[target.Name] = true --stores target to table for future check
--do stuff here
delay(.1,function() alreadyHit[target.Name] = nil end) --deletes target from the table
end
end)
2 Likes
Znimator
(znimator)
July 1, 2020, 5:18pm
#6
its good idea, but are you sure you wrote it right?
2sgo
(2sgo)
July 1, 2020, 5:23pm
#7
My mistake, I’ve made a typo. I’ve updated the code now.
Znimator
(znimator)
July 1, 2020, 5:24pm
#8
its still cant attack many targets
idk if u have already found a solution but this should do it
Attacked = {}
if not Attacked[table.find(Attacked,Target)] then
table.insert(Attacked,Target)
--stuff
for i =1 , #Attacked do
if Attacked[i] == Target then
table.remove(Attacked,i)
end
end
end
3 Likes
Unrelated to the scripting, but you have some z-fighting going on there on the stand and on your clothes - just thought you might want to fix that.