-
What do you want to achieve? Keep it simple and clear!
I want to make a sword combat system. -
What is the issue? Include screenshots / videos if possible!
The animations don’t play.
(I was clicking) -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I don’t think I need to search a website for that.
-- Wait for char
game.Players.LocalPlayer.CharacterAdded:Wait()
-- Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")
local UserInputService = game:GetService("UserInputService")
-- Modules
local Config = require(script.Parent.Parent.Modules.Config)
-- Tool
local Tool = script.Parent.Parent
local Handle = Tool:WaitForChild("Handle")
-- UI
local UI = Tool.Assets.UI
local CooldownUI = UI.CooldownUI
-- Sword Vars
local Damage = Config.Damage
local Cooldown = Config.Cooldown
-- Player Vars
local player, humanoid, char
char = Tool.Parent.Parent or Players.LocalPlayer.CharacterAdded:Wait() or Players.LocalPlayer.Character
player = Players.LocalPlayer
humanoid = player.Character:WaitForChild("Humanoid")
-- Anim Folder
local AnimFolder = Tool.Animations
-- Booleans
local isAttacking = false
local canDamage = true
-- Animation Instances
for i,v in pairs(Config.Animations.SlashAnimations) do
if not v.Enabled then continue end
local Anim = Instance.new("Animation")
Anim.Parent = AnimFolder
Anim.Name = i
Anim.AnimationId = v.AnimationId
end
for i,v in pairs(Config.Animations.OtherAnimations) do
if not v.Enabled then continue end
local Anim = Instance.new("Animation")
Anim.Parent = AnimFolder
Anim.Name = i
Anim.AnimationId = v.AnimationId
end
local function onEquip()
local EquipAnim = AnimFolder:WaitForChild("Equip")
local EquipTrack = humanoid:LoadAnimation(EquipAnim)
EquipTrack:Play()
end
-- Attack
local Combo = 1
local function Attack()
local Slash = humanoid:LoadAnimation(AnimFolder:WaitForChild("Slash" .. tostring(Combo)))
Slash:Play()
Tool.Remotes.ClientCast:FireServer(Slash.Length, Config.Cooldown)
canDamage = false
task.wait(math.max(Slash.Length, Config.Cooldown))
canDamage = true
end
UserInputService.InputBegan:Connect(function(input, gameProccessed)
if input.UserInputType == Enum.UserInputType.MouseButton1 and char:FindFirstChild(Tool.Name) then
if isAttacking == false and canDamage then
isAttacking = true
if Combo > 5 then
Combo = 1
end
Attack()
isAttacking = false
Combo += 1
end
end
end)
Tool.Equipped:Connect(onEquip)
This script is the whole local script. The slash animations are played from the Attack() function.