So I’m making a rpg game
What I’m trying to do is when a player or a npc is blocking the sword does less damage
But the sword still does the same damage
It does not give me any errors
The code:
-- Variables
local db = false
local damage = script.Parent.Damage.Value
local canHit = false
local randomSlash = 1
local idle
local slash
local running
-- Configure
local con = {
trailEnabled = true;
bloodEffects = true
}
-- Player Equip
script.Parent.Equipped:Connect(function()
script.Parent.Hitbox.Equip:Play()
local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
if not idle then idle = humanoid:LoadAnimation(script.Equip) end
idle:Play()
end)
-- The sword slashes
script.Parent.Activated:Connect(function()
if not db then
db = true
if con.trailEnabled == true then
script.Parent.Hitbox.Trail.Enabled = true
end
local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
if not slash then
if randomSlash == 1 then
slash = humanoid:LoadAnimation(script.Slash1)
randomSlash = randomSlash + 1
wait(0.2)
elseif randomSlash == 2 then
slash = humanoid:LoadAnimation(script.Slash2)
randomSlash = randomSlash + 1
wait(0.2)
elseif randomSlash == 3 then
slash = humanoid:LoadAnimation(script.Slash3)
randomSlash = randomSlash - 2
end
end
slash:Play()
wait(.2)
script.Parent.Hitbox.Slash:Play()
wait(.8)
if slash then
slash:Stop()
slash = nil
end
script.Parent.Hitbox.Trail.Enabled = false
db = false
end
end)
-- If the sword slash, the damage meets
script.Parent.Hitbox.Touched:Connect(function(hit)
if db then
if not canHit then
canHit = true
local effect = script.Parent.Hitbox.Effect:Clone()
if hit.Parent:FindFirstChild("Humanoid") then
local hitSFX = Instance.new("Sound",hit.Parent.Head); hitSFX.SoundId = "rbxassetid://566593606"; hitSFX:Play()
local block = hit.Parent:FindFirstChild("block")
if not block then
damage = 10
hit.Parent.Humanoid:TakeDamage(damage)
if con.bloodEffects == true then
effect.Parent = hit.Parent.HumanoidRootPart
effect.Enabled = true
end
elseif block then
if block == true then
damage = 5
wait(0.2)
hit.Parent.Humanoid:TakeDamage(damage)
if con.bloodEffects == true then
effect.Parent = hit.Parent.HumanoidRootPart
effect.Enabled = true
elseif block == false then
damage = 10
hit.Parent.Humanoid:TakeDamage(damage)
if con.bloodEffects == true then
effect.Parent = hit.Parent.HumanoidRootPart
effect.Enabled = true
end
end
end
end
end
wait(1)
effect:Destroy()
canHit = false
end
end
-- Stops Everything when we unequip
script.Parent.Unequipped:Connect(function()
if idle then idle:Stop() end
if slash then slash:Stop() end
end)
end)
-- Variables
local db = false
local damage = script.Parent.Damage.Value
local canHit = false
local randomSlash = 1
local idle
local slash
local running
-- Configure
local con = {
trailEnabled = true;
bloodEffects = true
}
-- Player Equip
script.Parent.Equipped:Connect(function()
script.Parent.Hitbox.Equip:Play()
local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
if not idle then idle = humanoid:LoadAnimation(script.Equip) end
idle:Play()
end)
-- The sword slashes
script.Parent.Activated:Connect(function()
if not db then
db = true
if con.trailEnabled == true then
script.Parent.Hitbox.Trail.Enabled = true
end
local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
if not slash then
if randomSlash == 1 then
slash = humanoid:LoadAnimation(script.Slash1)
randomSlash = randomSlash + 1
wait(0.2)
elseif randomSlash == 2 then
slash = humanoid:LoadAnimation(script.Slash2)
randomSlash = randomSlash + 1
wait(0.2)
elseif randomSlash == 3 then
slash = humanoid:LoadAnimation(script.Slash3)
randomSlash = randomSlash - 2
end
end
slash:Play()
wait(.2)
script.Parent.Hitbox.Slash:Play()
wait(.8)
if slash then
slash:Stop()
slash = nil
end
script.Parent.Hitbox.Trail.Enabled = false
db = false
end
end)
-- If the sword slash, the damage meets
script.Parent.Hitbox.Touched:Connect(function(hit)
if db then
if not canHit then
canHit = true
local effect = script.Parent.Hitbox.Effect:Clone()
if hit.Parent:FindFirstChild("Humanoid") then
local hitSFX = Instance.new("Sound",hit.Parent.Head); hitSFX.SoundId = "rbxassetid://566593606"; hitSFX:Play()
local block = hit.Parent:FindFirstChild("block")
if block.Value == false then
damage = 10
hit.Parent.Humanoid:TakeDamage(damage)
if con.bloodEffects == true then
effect.Parent = hit.Parent.HumanoidRootPart
effect.Enabled = true
end
elseif block then
if block.Value == true then
damage = 5
wait(0.2)
hit.Parent.Humanoid:TakeDamage(damage)
if con.bloodEffects == true then
effect.Parent = hit.Parent.HumanoidRootPart
effect.Enabled = true
elseif block == false then
damage = 10
hit.Parent.Humanoid:TakeDamage(damage)
if con.bloodEffects == true then
effect.Parent = hit.Parent.HumanoidRootPart
effect.Enabled = true
end
end
end
end
end
wait(1)
effect:Destroy()
canHit = false
end
end
-- Stops Everything when we unequip
script.Parent.Unequipped:Connect(function()
if idle then idle:Stop() end
if slash then slash:Stop() end
end)
end)
-- Variables
local db = false
local damage = script.Parent.Damage.Value
local canHit = false
local randomSlash = 1
local idle
local slash
local running
-- Configure
local con = {
trailEnabled = true;
bloodEffects = true
}
-- Player Equip
script.Parent.Equipped:Connect(function()
script.Parent.Hitbox.Equip:Play()
local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
if not idle then idle = humanoid:LoadAnimation(script.Equip) end
idle:Play()
end)
-- The sword slashes
script.Parent.Activated:Connect(function()
if not db then
db = true
if con.trailEnabled == true then
script.Parent.Hitbox.Trail.Enabled = true
end
local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
if not slash then
if randomSlash == 1 then
slash = humanoid:LoadAnimation(script.Slash1)
randomSlash = randomSlash + 1
wait(0.2)
elseif randomSlash == 2 then
slash = humanoid:LoadAnimation(script.Slash2)
randomSlash = randomSlash + 1
wait(0.2)
elseif randomSlash == 3 then
slash = humanoid:LoadAnimation(script.Slash3)
randomSlash = randomSlash - 2
end
end
slash:Play()
wait(.2)
script.Parent.Hitbox.Slash:Play()
wait(.8)
if slash then
slash:Stop()
slash = nil
end
script.Parent.Hitbox.Trail.Enabled = false
db = false
end
end)
-- If the sword slash, the damage meets
script.Parent.Hitbox.Touched:Connect(function(hit)
if db then
if not canHit then
canHit = true
local effect = script.Parent.Hitbox.Effect:Clone()
if hit.Parent:FindFirstChild("Humanoid") then
local hitSFX = Instance.new("Sound",hit.Parent.Head); hitSFX.SoundId = "rbxassetid://566593606"; hitSFX:Play()
local block = hit.Parent:FindFirstChild("block")
if not block then
damage = 10
hit.Parent.Humanoid:TakeDamage(damage)
if con.bloodEffects == true then
effect.Parent = hit.Parent.HumanoidRootPart
effect.Enabled = true
end
elseif block then
if block.Value == true then
damage = 5
wait(0.2)
hit.Parent.Humanoid:TakeDamage(damage)
if con.bloodEffects == true then
effect.Parent = hit.Parent.HumanoidRootPart
effect.Enabled = true
elseif block == false then
damage = 10
hit.Parent.Humanoid:TakeDamage(damage)
if con.bloodEffects == true then
effect.Parent = hit.Parent.HumanoidRootPart
effect.Enabled = true
end
end
end
end
end
wait(1)
effect:Destroy()
canHit = false
end
end
-- Stops Everything when we unequip
script.Parent.Unequipped:Connect(function()
if idle then idle:Stop() end
if slash then slash:Stop() end
end)
end)
I changed the code a bit now it does damage but the is a problem
When I hit a person blocking the damage value goes to 5 but if I hit a person again without blocking the value does not go back to 10
code:
-- Variables
local db = false
local UIS = game:GetService("UserInputService")
local damage = script.Parent.Damage.Value
local canHit = false
local randomSlash = 1
local idle
local slash
local running
-- Configure
local con = {
trailEnabled = true;
bloodEffects = true
}
-- Player Equip
script.Parent.Equipped:Connect(function()
script.Parent.Hitbox.Equip:Play()
local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
if not idle then idle = humanoid:LoadAnimation(script.Equip) end
idle:Play()
end)
-- The sword slashes
script.Parent.Activated:Connect(function()
if not db then
db = true
if con.trailEnabled == true then
script.Parent.Hitbox.Trail.Enabled = true
end
local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
if not slash then
if randomSlash == 1 then
slash = humanoid:LoadAnimation(script.Slash1)
randomSlash = randomSlash + 1
wait(0.2)
elseif randomSlash == 2 then
slash = humanoid:LoadAnimation(script.Slash2)
randomSlash = randomSlash + 1
wait(0.2)
elseif randomSlash == 3 then
slash = humanoid:LoadAnimation(script.Slash3)
randomSlash = randomSlash - 2
end
end
slash:Play()
wait(.2)
script.Parent.Hitbox.Slash:Play()
wait(.8)
if slash then
slash:Stop()
slash = nil
end
script.Parent.Hitbox.Trail.Enabled = false
db = false
end
end)
-- If the sword slash, the damage meets
script.Parent.Hitbox.Touched:Connect(function(hit)
if db then
if not canHit then
canHit = true
local effect = script.Parent.Hitbox.Effect:Clone()
if hit.Parent:FindFirstChild("Humanoid") then
local hitSFX = Instance.new("Sound",hit.Parent.Head); hitSFX.SoundId = "rbxassetid://566593606"; hitSFX:Play()
local block = hit.Parent.Humanoid:FindFirstChild("block")
if not block.Value then
hit.Parent.Humanoid:TakeDamage(damage)
if con.bloodEffects == true then
effect.Parent = hit.Parent.HumanoidRootPart
effect.Enabled = true
end
elseif block.Value then
if block.Value == true then
damage = 5
wait(0.2)
hit.Parent.Humanoid:TakeDamage(damage)
if con.bloodEffects == true then
effect.Parent = hit.Parent.HumanoidRootPart
effect.Enabled = true
elseif block.Value == false then
damage = 10
hit.Parent.Humanoid:TakeDamage(damage)
if con.bloodEffects == true then
effect.Parent = hit.Parent.HumanoidRootPart
effect.Enabled = true
end
end
end
end
end
wait(1)
effect:Destroy()
canHit = false
end
end
-- Stops Everything when we unequip
script.Parent.Unequipped:Connect(function()
if idle then idle:Stop() end
if slash then slash:Stop() end
end)
end)
-- Variables
local db = false
local UIS = game:GetService("UserInputService")
local damage = script.Parent.Damage.Value
local canHit = false
local randomSlash = 1
local idle
local slash
local running
-- Configure
local con = {
trailEnabled = true;
bloodEffects = true
}
-- Player Equip
script.Parent.Equipped:Connect(function()
script.Parent.Hitbox.Equip:Play()
local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
if not idle then idle = humanoid:LoadAnimation(script.Equip) end
idle:Play()
end)
-- The sword slashes
script.Parent.Click.OnServerEvent:Connect(function()
if not db then
db = true
if con.trailEnabled == true then
script.Parent.Hitbox.Trail.Enabled = true
end
local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
if not slash then
if randomSlash == 1 then
slash = humanoid:LoadAnimation(script.Slash1)
randomSlash = randomSlash + 1
wait(0.2)
elseif randomSlash == 2 then
slash = humanoid:LoadAnimation(script.Slash2)
randomSlash = randomSlash + 1
wait(0.2)
elseif randomSlash == 3 then
slash = humanoid:LoadAnimation(script.Slash3)
randomSlash = randomSlash - 2
end
end
slash:Play()
wait(.2)
script.Parent.Hitbox.Slash:Play()
wait(.8)
if slash then
slash:Stop()
slash = nil
end
script.Parent.Hitbox.Trail.Enabled = false
db = false
end
end)
-- If the sword slash, the damage meets
script.Parent.Hitbox.Touched:Connect(function(hit)
if db then
if not canHit then
canHit = true
local effect = script.Parent.Hitbox.Effect:Clone()
if hit.Parent:FindFirstChild("Humanoid") then
local hitSFX = Instance.new("Sound",hit.Parent.Head); hitSFX.SoundId = "rbxassetid://566593606"; hitSFX:Play()
local block = hit.Parent:FindFirstChild("block")
if not block.Value then
damage = 10
hit.Parent.Humanoid:TakeDamage(damage)
if con.bloodEffects == true then
effect.Parent = hit.Parent.HumanoidRootPart
effect.Enabled = true
end
elseif block.Value then
if block.Value == true then
damage = 5
wait(0.2)
hit.Parent.Humanoid:TakeDamage(damage)
if con.bloodEffects == true then
effect.Parent = hit.Parent.HumanoidRootPart
effect.Enabled = true
elseif block.Value == false then
damage = 10
hit.Parent.Humanoid:TakeDamage(damage)
if con.bloodEffects == true then
effect.Parent = hit.Parent.HumanoidRootPart
effect.Enabled = true
end
end
end
end
end
wait(1)
effect:Destroy()
canHit = false
end
end
-- Stops Everything when we unequip
script.Parent.Unequipped:Connect(function()
if idle then idle:Stop() end
if slash then slash:Stop() end
end)
end)