Created
July 30, 2021 17:07
-
-
Save RobertCodez/dc91cf405d429ae1b31f180ca367172b to your computer and use it in GitHub Desktop.
Sword Script | Weapons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local tool = script.Parent | |
local idleAnim = script:WaitForChild("Idle") | |
local idleAnimTrack | |
local swingAnim = script:WaitForChild("Swing") | |
local swingAnimTrack | |
local count = 1 | |
local slashSound = script:WaitForChild("SlashSound") | |
local sheathSound = script:WaitForChild("SheathSound") | |
local hitSound = script:WaitForChild("HitSound") | |
local hitCharacters = {} | |
local debounce = false | |
tool.Equipped:Connect(function() | |
local humanoid = script.Parent.Parent.Humanoid | |
if not idleAnimTrack then idleAnimTrack = humanoid:LoadAnimation(idleAnim) end | |
idleAnimTrack:Play() | |
sheathSound:Play() | |
end) | |
tool.Unequipped:Connect(function() | |
if idleAnimTrack then idleAnimTrack:Stop() end | |
if swingAnimTrack then swingAnimTrack:Stop() end | |
sheathSound:Play() | |
end) | |
tool.Activated:Connect(function() | |
if debounce then return end | |
debounce = true | |
local humanoid = script.Parent.Parent.Humanoid | |
if not swingAnimTrack then swingAnimTrack = humanoid:LoadAnimation(swingAnim) end | |
swingAnimTrack:Play() | |
wait(0.3) | |
slashSound:Play() | |
wait(0.5) | |
debounce = false | |
end) | |
for i,v in pairs(tool:GetChildren()) do | |
if v:IsA("BasePart") then | |
v.Touched:Connect(function(touch) | |
if hitCharacters[touch.Parent] or not debounce then return end | |
if touch.Parent:FindFirstChild("Humanoid") then | |
if touch.Name == "Head" then | |
touch.Parent.Humanoid:TakeDamage(30) | |
else | |
touch.Parent.Humanoid:TakeDamage(20) | |
end | |
hitSound:Play() | |
hitCharacters[touch.Parent] = true | |
wait(1) | |
hitCharacters[touch.Parent] = nil | |
end | |
end) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment