Hey there,
I’m working on a weapon script that features blocking, disarming, and even a system where, if you have the correct manual in your ‘inventory’, you get better animations.
However, I’ve been scripting on it for a few days now, and I’ve noticed either one of three problems occur:
- Either the weapon does damage even when the CanAttack debounce doesn’t allow it to do so.
- Either the weapon does no damage at all.
- Either the weapon does way too much damage in a single swing or touch.
Currently the script gives the second problem, I’ve tried toying around with values and debounce alot, but to no avail. Ideally, the weapon should do a single chunk damage only when it’s animation plays. Any help would be greatly appreciated. Here’s the scripts:
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
LOCAL SCRIPT:
local AttackEvent = tool:WaitForChild("Attack")
local holdEvent = tool:WaitForChild("Equip")
local UnequipEvent = tool:WaitForChild("Unequip")
local equipped = false
local ready = true
local blockReady = true
local disarmReady = true
local function unEquipFalse()
if game.Players.LocalPlayer.PlayerGui:FindFirstChild("Menu") then
game.Players.LocalPlayer.PlayerGui.Menu.Enabled = false
end
end
local function unEquipTrue()
if game.Players.LocalPlayer.PlayerGui:FindFirstChild("Menu") then
game.Players.LocalPlayer.PlayerGui.Menu.Enabled = true
end
end
tool.Equipped:Connect(function()
if equipped == false then
equipped = true
holdEvent:FireServer()
end
end)
tool.Unequipped:Connect(function()
UnequipEvent:FireServer()
equipped = false
end)
tool.Activated:Connect(function()
if ready == true then
ready = false
AttackEvent:FireServer()
wait (1.2)
ready = true
end
end)
-- blocking starts here
function onKeyPress(inputObject, gameProcessedEvent)
if equipped == true then
if inputObject.KeyCode == Enum.KeyCode.R then
unEquipFalse()
if blockReady == true then
blockReady = false
tool.Block:FireServer()
wait(1.35)
blockReady = true
unEquipTrue()
end
end
end
-- disarming starts here
if equipped == true then
if inputObject.KeyCode == Enum.KeyCode.F then
if disarmReady == true then
if blockReady == true then
disarmReady = false
tool.DisarmOpponent:FireServer()
wait(2)
disarmReady = true
end
end
end
end
end
game:GetService("UserInputService").InputBegan:Connect(onKeyPress)
SERVER SCRIPT:
math.randomseed(tick())
local players = game:GetService("Players")
local tool = script.Parent
local AttackEvent = tool.Attack
local animations = {2767602406,2768855848,2768933359}
local clumsyAnim = {3568954918,3568954918}
local holdEvent = tool.Equip
local unEquipEvent = tool.Unequip
--local touched = false
local blockEvent = tool.Block
local disarmEvent = tool.DisarmOpponent
local canAttack = true
local disarmOpponentAnimation = script.Parent.Anims.DisarmOpponent
local manualRequired = script.Parent.ManualRequired
local function onHoldFired(plr)
plr.Character.Humanoid["IsDisarmable"].Value = false
local animHold = script.Parent.Anims.Hold
local animHoldLoop = plr.Character.Humanoid:LoadAnimation(animHold)
animHoldLoop:Play()
end
local function onUnequipFired(plr)
local humanoid = plr.Character.Humanoid
local ActiveTracks = humanoid:GetPlayingAnimationTracks()
for _,v in pairs(ActiveTracks) do
v:Stop()
end
end
local function onAttackFired(plr)
local canAttack = true
if canAttack == true then
canAttack = false
local char = plr.Character
local humanoid = char.Humanoid
local animation = Instance.new("Animation")
local picked = math.random(1, #animations)
if plr.Manuals:FindFirstChild(manualRequired.Value) then
animation.AnimationId = "http://roblox.com/asset/?id="..animations[picked]
local animTrack = humanoid:LoadAnimation(animation)
animTrack:Play()
script.Parent.Handle.SwingSound:Play()
plr.Character.Humanoid["IsDisarmable"].Value = true
wait(script.Parent.DisarmingTimeWindow.Value)
plr.Character.Humanoid["IsDisarmable"].Value = false
elseif not plr.Manuals:FindFirstChild(manualRequired.Value) then
animation.AnimationId = "http://roblox.com/asset/?id=".. clumsyAnim[picked]
local animTrack = humanoid:LoadAnimation(animation)
animTrack:Play()
script.Parent.Handle.SwingSound:Play()
plr.Character.Humanoid["IsDisarmable"].Value = true
wait(script.Parent.DisarmingTimeWindow.Value)
plr.Character.Humanoid["IsDisarmable"].Value = false
end
end
tool.Blade.Touched:Connect(function(part)
if part.Parent:FindFirstChild("Humanoid") and part.Parent.Humanoid:FindFirstChild("CanEngageInPVP")then
if part.Parent.Humanoid["CanEngageInPVP"].Value == true then
if touched == false then
-- if opponent is blocking
if part.Parent.Humanoid:FindFirstChild("IsBlocking") and part.Parent.Humanoid:FindFirstChild("IsBlocking").Value == true then
--part.Parent.Humanoid:TakeDamage(2) -- (this could serve as defense penentration)
tool.Handle.BlockSound:Play()
tool.Blade.Sparkles.Enabled = true
wait(0.1)
tool.Blade.Sparkles.Enabled = false
wait(0.9)
canAttack = true
touched = false
-- if opponent is not blocking
elseif part.Parent.Humanoid:FindFirstChild("IsBlocking") and part.Parent.Humanoid:FindFirstChild("IsBlocking").Value == false then
if plr.Manuals:FindFirstChild(manualRequired.Value) then
part.Parent:FindFirstChild("Humanoid"):TakeDamage(script.Parent.Damage.Value - part.Parent["Humanoid"].ArmourLevel.Value/script.Parent.AntiArmourCapacity.Value)-- the higher the number, the better it penentrates armour
elseif not plr.Manuals:FindFirstChild(manualRequired.Value) then
part.Parent:FindFirstChild("Humanoid"):TakeDamage(script.Parent.Damage.Value - part.Parent["Humanoid"].ArmourLevel.Value/script.Parent.AntiArmourCapacity.Value/100*80)-- the higher the number, the better it penentrates armour
end
part.Parent["Humanoid"]["WhoKilled"].Value = plr.Name -- for the exp system
tool.Handle.HitSound:Play()
wait(1)
canAttack = true
else
wait(1)
canAttack = true
end
end
end
end
end)
end
local function disarmTouch()
local disarmTouched = false
tool.Blade.Touched:Connect(function(part)
if part.Parent:FindFirstChild("Humanoid") then
if part.Parent["Humanoid"].CanEngageInPVP == true then
if disarmTouched == false then
disarmTouched = true
if part.Parent.Humanoid["IsDisarmable"].Value == true then
local opponent = players:GetPlayerFromCharacter(part.Parent)
if opponent.Character:FindFirstChildOfClass("Tool") then
local opponentItem = opponent.Character:FindFirstChildOfClass("Tool")
local itemName = opponentItem.Name
opponent.Character["Humanoid"]:UnequipTools()
opponentItem:Destroy()
opponent.Storage:FindFirstChild(itemName):Destroy()
local item = game.ReplicatedStorage.Objects:FindFirstChild(itemName):Clone()
item.Position = part.Parent.LeftHand.Position
local OpponentDisarmPlay = opponent.Character["Humanoid"]:LoadAnimation(disarmOpponentAnimation)
OpponentDisarmPlay:Play()
item.Parent = game.Workspace
tool.Blade.Sparkles.Enabled = true
tool.Handle.Disarm:Play()
wait(0.2)
tool.Blade.Sparkles.Enabled = false
wait(OpponentDisarmPlay.Length + 0.5)
local ActiveTracks = opponent.Character.Humanoid:GetPlayingAnimationTracks()
for _,v in pairs(ActiveTracks) do
v:Stop()
end
end
end
end
end
end
end)
wait(0.1)
tool.Blade.Sparkles.Enabled = false
touched = false
disarmTouched = false
end
--blocking
local function onBlockFired(plr)
plr.Character.Humanoid.IsBlocking.Value = true
plr.Character.Humanoid.WalkSpeed = 7.3
local animBlock = script.Parent.Anims.Block
local animBlockPlay = plr.Character.Humanoid:LoadAnimation(animBlock)
animBlockPlay:Play()
wait(animBlockPlay.Length)
plr.Character.Humanoid.WalkSpeed = plr.Character.Humanoid.MovementSpeed.Value
plr.Character.Humanoid.IsBlocking.Value = false
end
--disarming
local function onDisarmFired(plr)
plr.Character.Humanoid.WalkSpeed = 0
local animDisarm = script.Parent.Anims.Disarm
local animDisarmPlay = plr.Character.Humanoid:LoadAnimation(animDisarm)
animDisarmPlay:Play()
disarmTouch()
wait(animDisarmPlay.Length)
plr.Character.Humanoid.WalkSpeed = plr.Character.Humanoid.MovementSpeed.Value
end
holdEvent.OnServerEvent:Connect(onHoldFired)
unEquipEvent.OnServerEvent:Connect(onUnequipFired)
AttackEvent.OnServerEvent:Connect(onAttackFired)
blockEvent.OnServerEvent:Connect(onBlockFired)
disarmEvent.OnServerEvent:Connect(onDisarmFired)
Really, I’ve run out of ideas and options, I’d really appreciate some help. If you’ve got any questions about the script or I’m not being clear - feel free to ask in the comments.
Thank you!
- Souflee