I need my hitbox to be more exact to thee actual part.
i have an invisible box name “damagepart” the script uses a touched event and it plays an animation also. long story short, I dont know what i’m doing. Its so buggy, its my first time making a melee tool.
local script:
local firstswing = game.ReplicatedStorage.greatswordevents.firstswing
local idleevent = game.ReplicatedStorage.greatswordevents.idleevent
local endidle = game.ReplicatedStorage.greatswordevents.endidle
local secondswing = game.ReplicatedStorage.greatswordevents.secondswing
local swingsound = game.ReplicatedStorage.sound.heavyswing
local function playsound()
wait(0.4)
swingsound:Play()
end
local swing = true
local candamage = false
local db = false
script.Parent.Equipped:Connect(function()
idleevent:FireServer()
end)
script.Parent.Unequipped:Connect(function()
endidle:FireServer()
end)
script.Parent.Activated:Connect(function()
if db == false then
if swing == true then
firstswing:FireServer()
swing = false
elseif swing == false then
secondswing:FireServer()
swing = true
end
db = true
task.wait(1.75)
db = false
end
end)
script.Parent.Activated:Connect(function()
if db == false then
if swing == true then
playsound()
elseif swing == false then
playsound()
end
end
script.Parent["big sword"].blade.damagepart.Touched:Connect(function(hit)
end)
end)
server script:
local damagepart = script.Parent["big sword"].blade:FindFirstChild("damagepart")
local candamage = false
local db = false
local swing = true
--swing true means first swing for the "combo" flase = second swing
script.Parent.Activated:Connect(function()
if db == false and swing == false then
db = true
task.wait(0.24)--wait for animation to swing
candamage = true
task.wait(0.5) -- make damage while swing
candamage = false
wait(0.5) --swing cd after swing finishes
db = false
swing = true
elseif db == false and swing == true then
db = true
task.wait(0.24)--wait for animation to swing
candamage = true
task.wait(0.20) -- make damage while swing
candamage = false
wait(1) --swing cd after swing finishes
db = false
swing = false
end
end)
damagepart.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
if candamage == true then
Humanoid.Health = Humanoid.Health -10
candamage = false
local effect = game.ReplicatedStorage.hiteffect:Clone()
effect.Parent = workspace
effect.Position = hit.Position
end
end
end)
local damagepart = script.Parent["big sword"].blade:FindFirstChild("damagepart")
local candamage = false
local db = false
local swing = true
--swing true means first swing for the "combo" flase = second swing
script.Parent.Activated:Connect(function()
if db == false and swing == false then
db = true
task.wait(0.24)--wait for animation to swing
candamage = true
task.wait(0.5) -- make damage while swing
candamage = false
wait(0.5) --swing cd after swing finishes
db = false
swing = true
elseif db == false and swing == true then
db = true
task.wait(0.24)--wait for animation to swing
candamage = true
task.wait(0.20) -- make damage while swing
candamage = false
wait(1) --swing cd after swing finishes
db = false
swing = false
end
end)
damagepart.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
if candamage == true then
Humanoid.Health = Humanoid.Health -10
candamage = false
local effect = game.ReplicatedStorage.hiteffect:Clone()
effect.Parent = workspace
effect.Position = hit.Position
end
end
end)