I don’t know how to turn this into word form, but when you attack once it works alright, however if you still hold LMB after the 1st attack the 2nd attack fires twice. and with the 3rd attack it fires 3 times and so on. I don’t want this and I want to avoid this, please help!
The local script.
local rs = game:GetService("ReplicatedStorage")
local uis = game:GetService("UserInputService")
local tween = game:GetService("TweenService")
local attackfolder = rs.AttackFolder
local anims = script.Parent.Folder
local attackanim = anims.Attack1
local idle = anims.Idle
local plr = game:GetService("Players").LocalPlayer
local mouse = plr:GetMouse()
local char = plr.Character
local hum = char:FindFirstChild("Humanoid")
local attack = hum:LoadAnimation(attackanim)
local hrp = char.HumanoidRootPart
local animate = char:WaitForChild("Animate")
if animate then
animate.idle.Animation1.AnimationId = idle.AnimationId
animate.idle.Animation2.AnimationId = idle.AnimationId
end
local db = {
["Global"] = false;
["Basic"] = false;
["E"] = false;
["R"] = false;
["F"] = false;
}
local MouseDown = false
uis.InputBegan:Connect(function(i,gp)
if i.UserInputType == Enum.UserInputType.MouseButton1 and not gp then
MouseDown = true
while MouseDown == true do
if db["Global"] == false and db["Basic"] == false then
attack:Play()
db["Global"] = true
db["Basic"] = true
attack.KeyframeReached:Connect(function(name)
if name == "StartAttack" or name == "AttackEnd" then
print(name)
attackfolder.Attack1:FireServer(name)
elseif name == "AnimEnd" then
print(name)
local dbc = coroutine.create(function()
task.wait(.3)
db["Global"] = false
task.wait(.7)
db["Basic"] = false
end)
coroutine.resume(dbc)
end
end)
end
task.wait()
end
end
end)
uis.InputEnded:Connect(function(i,gp)
if i.UserInputType == Enum.UserInputType.MouseButton1 and not gp then
MouseDown = false
end
end)
The Serverscript.
local rs = game:GetService("ReplicatedStorage")
local attackfolder = rs.AttackFolder
attackfolder.Attack1.OnServerEvent:Connect(function(user,keyframe)
local char = user.Character
local hum = char:WaitForChild("Humanoid")
local hitbox = script.Parent.Hitbox:Clone()
if keyframe == "StartAttack" then
local damage = 30
hitbox.Parent = script.Parent.Blade
hitbox.Position = script.Parent.Blade.Position
local hitanti = {}
if keyframe == "StartAttack" then
hitbox.Touched:Connect(function(hit)
if hit.Parent.Name ~= char.Name and hit.Parent:FindFirstChild("Humanoid") and not table.find(hitanti,hit.Parent.Name) then
local hum = hit.Parent.Humanoid
hum:TakeDamage(damage)
table.insert(hitanti,hit.Parent.Name)
end
end)
end
elseif keyframe == "AttackEnd" then
hitbox:Destroy()
end
end)```