Hi, I hope you have a good day. So, basically, I have this sword local script that allows me to fire an animation of the sword slashing and then return to an idol state. That works perfectly fine. However, I have another script that tells you how much damage to do when firing the local script (in this case, I put my damage as a number between 30 and 40), but when I click it fires the animation but doesn't do any damage to a player. Please send help.
Local Script Code:
local CanAttack = true
script.Parent.Equipped:Connect(function()
local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack)
idle:Play()
end)
script.Parent.Activated:Connect(function()
local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack)
if CanAttack == true then
attack:Play()
idle:Stop()
CanAttack = false
wait(0.7)attack:Stop()
idle:Play()
CanAttack = true
script.Parent.CanDamage.Value = true
end
end)
Script Code:
script.Parent.Blade.Touched:Connect(function(p)
print(p)
if script.Parent.CanDamage.Value == true then
script.Parent.CanDamage.Value = false
if p.Parent:FindFirstChild("Humanoid") then
p.Parent.Humanoid:TakeDamage(math.random(30,40))
script.Parent.CanDamage.Value = true
end
end
end)
