I’m trying to make a sword that makes a horizontal swing animation. The original animation for the classic roblox sword makes it swing down and it works, however when I change the animation ID to my animation of the sword swinging sideways, nothing happens? I’ve tried placing print statements in front of the different parts that include the animation and all of them play just fine. The animations seem to play but I see nothing. I’m not sure why nothing is happening, so here is the code:
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local humanoidsTouchedBySwing = {}
local currentlySwinging = false
function Create(ty)
return function(data)
local obj = Instance.new(ty)
for k, v in pairs(data) do
if type(k) == 'number' then
v.Parent = obj
else
obj[k] = v
end
end
return obj
end
end
local BaseUrl = "rbxassetid://"
local Players = game:GetService("Players")
local Debris = game:GetService("Debris")
local RunService = game:GetService("RunService")
local Damage = 10
-- For R15 avatars
local Animations = {
R15Slash = 13850861557
-- 522635514 <OLD ANIMATION ID (is working)
-- 13850861557 <NEW ANIMATION ID (not working)
}
local Grips = {
Up = CFrame.new(0, 0, -1.70000005, 0, 0, 1, 1, 0, 0, 0, 1, 0),
Out = CFrame.new(0, 0, -1.70000005, 0, 1, 0, 1, -0, 0, 0, 0, -1)
}
local Sounds = {
Slash = Handle:WaitForChild("SwordSlash"),
Unsheath = Handle:WaitForChild("Unsheath")
}
local ToolEquipped = false
local Character, Player, Humanoid, Torso
local Track
Tool.Grip = Grips.Up
function IsTeamMate(Player1, Player2)
return (Player1 and Player2 and not Player1.Neutral and not Player2.Neutral and Player1.TeamColor == Player2.TeamColor)
end
function TagHumanoid(humanoid, player)
local Creator_Tag = Instance.new("ObjectValue")
Creator_Tag.Name = "creator"
Creator_Tag.Value = player
Debris:AddItem(Creator_Tag, 2)
Creator_Tag.Parent = humanoid
end
function UntagHumanoid(humanoid)
for i, v in pairs(humanoid:GetChildren()) do
if v:IsA("ObjectValue") and v.Name == "creator" then
v:Destroy()
end
end
end
local function CheckIfAlive()
return (((Player and Player.Parent and Character and Character.Parent and Humanoid and Humanoid.Parent and Humanoid.Health > 0 and Torso and Torso.Parent) and true) or false)
end
function Blow(Hit)
if not Hit or not Hit.Parent or not CheckIfAlive() or not ToolEquipped then
return
end
local RightArm = Character:FindFirstChild("Right Arm") or Character:FindFirstChild("RightHand")
if not RightArm then
return
end
local RightGrip = RightArm:FindFirstChild("RightGrip")
if not RightGrip or (RightGrip.Part0 ~= Handle and RightGrip.Part1 ~= Handle) then
return
end
local character = Hit.Parent
if character == Character then
return
end
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid or humanoid.Health == 0 then
return
end
local player = Players:GetPlayerFromCharacter(character)
if player and (player == Player or IsTeamMate(Player, player)) then
return
end
local alreadyTouchedThisSwing = false
for i, v in ipairs(humanoidsTouchedBySwing) do
if v == humanoid then
alreadyTouchedThisSwing = true
end
end
if alreadyTouchedThisSwing == true then
return
end
if currentlySwinging == false then
return
end
UntagHumanoid(humanoid)
TagHumanoid(humanoid, Player)
table.insert(humanoidsTouchedBySwing, humanoid)
humanoid:TakeDamage(Damage)
end
local function Attack()
Sounds.Slash:Play()
--[[
if Humanoid and Humanoid.RigType == Enum.HumanoidRigType.R15 and Track then
Track:Play(0)
end
--]]
end
local lastAttackTime = time()
local function HandleAnimationStopped()
currentlySwinging = false
humanoidsTouchedBySwing = {}
end
local function Activated()
if time() - lastAttackTime <= 0.5 or not ToolEquipped or not CheckIfAlive() then
return
end
currentlySwinging = true
lastAttackTime = time()
Attack()
local SlashAnim = (Tool:FindFirstChild("R15Slash") or Create("Animation") {
Name = "R15Slash",
AnimationId = BaseUrl .. Animations.R15Slash,
Parent = Tool
})
if Humanoid and Humanoid.RigType == Enum.HumanoidRigType.R15 and SlashAnim then
local AnimationTrack = Humanoid:LoadAnimation(SlashAnim)
AnimationTrack:Play(0)
AnimationTrack.Stopped:Connect(HandleAnimationStopped)
end
end
local function Equipped()
Character = Tool.Parent
Player = Players:GetPlayerFromCharacter(Character)
Humanoid = Character:FindFirstChildOfClass("Humanoid")
Torso = Character:FindFirstChild("HumanoidRootPart") or Character:FindFirstChild("Torso")
if not CheckIfAlive() then
return
end
ToolEquipped = true
Sounds.Unsheath:Play()
local animation = Instance.new("Animation")
animation.AnimationId = BaseUrl .. Animations.R15Slash
Track = Humanoid:LoadAnimation(animation)
Track.Stopped:Connect(HandleAnimationStopped)
end
local function Unequipped()
Tool.Grip = Grips.Up
ToolEquipped = false
end
Tool.Activated:Connect(Activated)
Tool.Equipped:Connect(Equipped)
Tool.Unequipped:Connect(Unequipped)
Handle.Touched:Connect(Blow)