So basically, I have a punch script, that is meant to take damage from a humanoid and if an animation is playing it will not.
Script:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local humanoid = player.Character:FindFirstChild("Humanoid")
local animate
local part = humanoid.Parent:WaitForChild("RightHand")
local connection
local db = false
local animated
local function round(n)
return math.floor(n + 0.5)
end
part.Touched:Connect(function(hit)
if db == false then
--Cannot Punch
elseif db == true then
if hit.Parent.Humanoid then
**if not hit.Parent.LocalAnimation then**
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - round(player.leaderstat.Strength.Value / 100)
print("Hit")
local animator = Instance.new("Animation", hit.Parent)
animator.AnimationId = "rbxassetid://5390143931"
animated = hit.Parent.Humanoid:LoadAnimation(animator)
animated:Play()
db = false
end
else
print("Not a humanoid!")
end
end
end)
mouse.KeyDown:Connect(function(key)
if key == "z" then
local animation = Instance.new("Animation", player.Character)
animation.AnimationId = "rbxassetid://5390069207"
animation.Name = "PunchAnim"
animate = humanoid:LoadAnimation(animation)
animate:Play()
game.ReplicatedStorage.Event.AddStrength:FireServer()
db = true
wait(0.5)
db = false
end
end)
It keeps saying error at the line with asterisks, that is line 18.
EDIT: Sorry I meant line 19

1 comment
First off, you could just do "if not db then" or however you handle it. Second off, what did the error say.