I am currently remaking a axe, which has a 1/20 (5%) of doing a critical hit which does 50 damage, currently I only made the critical hit, I decided to test It out however, It appears to not do anything
Script:
----Scripted by imnotaguest1121-----
local Tool = script.Parent ---Tool
local Debounce = false ---Debounce Is basically cooldown
local CanDamage = false ---Tells the tool If It can damage
local Animations = { ----Used a table to store all animations
Idle = Tool.Idle
Cut = Tool.Cut
CriticalCut = Tool["Critical Cut"]
}
local Sounds = { ----Table for sounds
Woosh = Tool.Woosh
HitSound = Tool.HitSound
HeadCut = Tool.HEADEXPLOSION
}
Tool.Activated:Connect(function() ---When the tool Is activated
if not Debounce then ---Or for better understanding, if Debounce == false then
Debounce = true ----Debounce ready
local CriticalHitOrNot = math.random(20,20) ---This creates a function that determains If the player does a critical hit or not
if CriticalHitOrNot == 20 then ---If the math.random() number Is 20 then
CanDamage = true ---Allows tool to damage
local Hum = Tool.Parent.Humanoid ---The humanoid of the player who Is currently equipped with the axe
local AnimationTrack = Hum:FindFirstChild("Animator"):LoadAnimation(Animations[3]) ---Makes a AnimationTrack, which Is used to play the animation using Animator:LoadAnimation
--[[It was originally easier to simply do local AnimationTrack = Hum:LoadAnimation(Animations[2]) but since Hum(anoid):LoadAnimation won't work anymore (If your using It on new work ofc)
]]
AnimationTrack:Play() ---Plays animation
Tool.Handle.Touched:Connect(function(hit) ----When a victim gets hit by axe
--This Is optional but I decided to use It just Incase Its a Team vs Team (TvT) game, like brickbattle
local player1 = game.Players:GetPlayerFromCharacter(hit.Parent)
local player2 = game.Players:GetPlayerFromCharacter(Tool.Parent)
if (player1 ~= nil) and (player2 ~= nil) then
local humanoid = (player2.Character or player2.CharacterAdded:Wait()):FindFirstChildWhichIsA("Humanoid")
if (player1.TeamColor ~= player2.TeamColor) then
if (humanoid ~= nil) and CanDamage == true then
humanoid:TakeDamage(50)
CanDamage = false
end
end
end
end)
Tool.Handle.Touched:Connect(function(hit) ---When a victim gets hit by axe, this Is for NPCS
local humanoid = hit.Parent:WaitForChild("Humanoid") ---Gets humanoid
--[[ You would also use FindFirstChild(WhichIsA)
(Note: Don't add the () when uisng FindFirstChildWhichIsA)
]]
if humanoid and CanDamage == true then ---If Its a humanoid and Candamage Is true
HeadCut:Play() ---Plays the critical hitsound
humanoid:TakeDamage(50) ----Does 50 damage, change the number to change how much damage It does
CanDamage = false ---Stops the tool from damaging
end
end)
end
end
end)
