-
What do you want to achieve I am making a simple knife script that does damage to people who touch the blade.
-
What is the issue? It does damage the first time I hit someone but after that it doesn’t work, I think this is because at first the bool is set to true, meaning it works and then somehow it gets set to false and stays false? not sure
Ive tried a lot of solutions, for hours.
The Local Script:
Damage Script:
Local Script Formatted:
local Knife = script.Parent.Parent
local Blade = Knife.Blade
local Handle = Knife.Handle
local SlashAnim = Knife.Animations.Slash
local EquipSound = Handle.Equip
local HitSound = Handle.Hit
local SlashSound = Handle.Slash
local UnEquipSound = Handle.UnEquip
local CanDamage = script.Parent.Parent.Values.CanDamage.Value
local Cooldown = Knife.Values.Cooldown.Value
local CooldownWait = 1
Knife.Equipped:Connect(function()
EquipSound:Play()
end)
Knife.Unequipped:Connect(function()
UnEquipSound:Play()
end)
Knife.Activated:Connect(function()
local Humanoid = Knife.Parent:FindFirstChildWhichIsA('Humanoid')
if Humanoid and Cooldown == false then
Cooldown = true
CanDamage = true
local PlaySlashAnim = Humanoid:LoadAnimation(SlashAnim)
PlaySlashAnim:Play()
wait(0.3)
SlashSound:Play()
wait(CooldownWait)
Cooldown = false
CanDamage = false
end
end)
Damage Script Formatted:
local Knife = script.Parent.Parent
local CanDamage = script.Parent.Parent.Values.CanDamage.Value
Knife.Blade.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and CanDamage == true then
hit.Parent.Humanoid:TakeDamage(5)
print("yes")
else
print("nos")
return
end
CanDamage = false
end)