I’m trying to make a sword that has 2 alternating animations.Thing is, I thought the damage was working fine until I tested it longer and it started to damage even if it was not activated yet.
Client:
local tool = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local remoteEvent = tool.RemoteEvent
local slash = tool.Slash
local slash2 = tool.Slash2
local slashTrack = animator:LoadAnimation(slash)
local slash2Track = animator:LoadAnimation(slash2)
local cooldown = false
local i = 1
tool.Activated:Connect(function()
if not cooldown then
cooldown = true
if i == 1 then
i += 1
slashTrack:Play()
else
i = 1
slash2Track:Play()
end
remoteEvent:FireServer()
wait(1)
cooldown = false
end
end)
Server:
local tool = script.Parent
local remoteEvent = tool.RemoteEvent
local handle = tool.Handle
local swing = handle.Swing
local hitSound = handle.Hit
local debounce = false
local slash
remoteEvent.OnServerEvent:Connect(function(player)
swing:Play()
slash = handle.Touched:Connect(function(hit)
local character = hit.Parent
local humanoid = character:FindFirstChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(character)
if humanoid and not debounce then
debounce = true
humanoid:TakeDamage(20)
hitSound:Play()
wait(1)
debounce = false
end
end)
wait(1)
slash:Disconnect()
end)