What do you want to achieve? Keep it simple and clear!
How do I make my sword only hit once and deal 22 damage to the npc instead of instant kill them
What is the issue? Include screenshots / videos if possible!
The sword just instant kill the dummy
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Adding debouce but doesn’t seems to work
local tool = script.Parent
local deb = false
local combo = 1
local Particle = script.Parent.Handle.Attachment1.ParticleEmitter
local HiEffect = require(game.ServerStorage:WaitForChild("HitEffectModule"))
local trail = script.Parent.Handle.Trail
tool.Activated:Connect(function()
if deb == false then
deb = true
local char = script.Parent.Parent
local humrp = char:WaitForChild("HumanoidRootPart")
local hum = char:WaitForChild("Humanoid")
trail.Enabled = true
Particle.Enabled = true
if combo == 1 then
local Anim = script.Swing1
local Track = hum:LoadAnimation(Anim)
Track:Play()
combo = 2
else
local Anim = script.Swing2
local Track = hum:LoadAnimation(Anim)
Track:Play()
combo = 1
end
local sound = script.M1
sound:Play()
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(10000,10000,10000)
bv.Velocity = (humrp.CFrame.lookVector * 15)
bv.Parent = humrp
hum.WalkSpeed = 0
local canhit = true
script.Parent.Handle.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if hit.Parent ~= char then
if canhit == true then
local thumrp = hit.Parent.HumanoidRootPart
local sound = script.M1hit
sound:Play()
HiEffect.Gore1(thumrp)
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(11000,11000,11000)
bv.Velocity = (humrp.CFrame.lookVector * 50)
bv.Parent = thumrp
hit.Parent.Humanoid:TakeDamage(22)
wait(0.1)
bv:Destroy()
canhit = false
end
end
end
end)
wait(0.2)
bv:Destroy()
wait(0.1)
hum.WalkSpeed = 16
trail.Enabled = false
Particle.Enabled = false
canhit = true
deb = false
end
end)
The code is in a normal script in a tool
The problem :
also if you know how to make it so that the sword only hit 1 dummy per swing, please tell how to do it too, I would be very appreciated
Add a debounce when the sword causes any damage to an opposing player. Make sure further damage can’t be dealt by that sword until the debounce has expired, I know you mentioned you tried using one but if you used it correctly then it would work.
local tool = script.Parent
local deb = false
local combo = 1
local Particle = script.Parent.Handle.Attachment1.ParticleEmitter
local HiEffect = require(game.ServerStorage:WaitForChild("HitEffectModule"))
local trail = script.Parent.Handle.Trail
tool.Activated:Connect(function()
if deb == false then
deb = true
local char = script.Parent.Parent
local humrp = char:WaitForChild("HumanoidRootPart")
local hum = char:WaitForChild("Humanoid")
trail.Enabled = true
Particle.Enabled = true
if combo == 1 then
local Anim = script.Swing1
local Track = hum:LoadAnimation(Anim)
Track:Play()
combo = 2
else
local Anim = script.Swing2
local Track = hum:LoadAnimation(Anim)
Track:Play()
combo = 1
end
local sound = script.M1
sound:Play()
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(10000,10000,10000)
bv.Velocity = (humrp.CFrame.lookVector * 15)
bv.Parent = humrp
hum.WalkSpeed = 0
local canhit = true
local HittedHum = nil
script.Parent.Handle.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if hit.Parent ~= char then
if canhit == true then
if HittedHum == nil then
HittedHum = hit.Parent.Humanoid
local thumrp = hit.Parent.HumanoidRootPart
local sound = script.M1hit
sound:Play()
HiEffect.Gore1(thumrp)
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(11000,11000,11000)
bv.Velocity = (humrp.CFrame.lookVector * 50)
bv.Parent = thumrp
hit.Parent.Humanoid:TakeDamage(22)
wait(0.1)
bv:Destroy()
canhit = false
end
end
end
end
end)
wait(0.2)
bv:Destroy()
wait(0.1)
hum.WalkSpeed = 16
trail.Enabled = false
Particle.Enabled = false
canhit = true
deb = false
end
end)
I tried to make minimum change to the code.
Take note of the HittedHum section
All these time i was replying to the wrong person lol @Fizzavocadoo
Your sword is insta killing because your Touch Event is firing without limit.
You need to add the debounce to the touch, not the Activate Event.
Also, this has been mentioned, you need to move your touch Event outside of Activate, because every time you click, you create a new touch, which will multiply your damage every time.