I’m trying to make a sword but the thing is, for some reason, it only damages once every two .Activated
. Please help, thanks much!
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(cooldown)
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 slash
remoteEvent.OnServerEvent:Connect(function(player, cooldown)
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 cooldown then
cooldown = false
humanoid:TakeDamage(20)
hitSound:Play()
end
slash:Disconnect()
end)
end)