Im trying to make a sword slash animation and im following this tutorial.
My problem is that the animation wont show up. I got back to Lua scripting after a Long while so im kinda “new” again but i cant find a mistake in my code maybe someone can help me.
swingAnims = {
'rbxassetid://11414802020', --1
'rbxassetid://11414802020', --2
'rbxassetid://11414802020', --3
'rbxassetid://11414802020', --4
'rbxassetid://11414802020', --5
}
local tween_service = game:GetService("TweenService")
local replicated_storage = game:GetService("ReplicatedStorage")
local user_input_service = game:GetService("UserInputService")
local resources = replicated_storage:WaitForChild("Weapons"):WaitForChild("Katana"):WaitForChild("Default")
local fx = resources:WaitForChild("Fx")
local remote = replicated_storage:WaitForChild("Remotes"):WaitForChild("Combat")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local root_part = character:WaitForChild("HumanoidRootPart")
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local current_swing = 1
local cooldown = false
local anim = script:WaitForChild("Animation")
local function slash(character, swing)
end
user_input_service.InputBegan:Connect(function(input, gpe)
if gpe then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 and cooldown == false and character:FindFirstChild("Stun") == nil then
if current_swing > 4 then
current_swing = 1
end
cooldown = true
print("should play animation now")
anim.AnimationId = swingAnims[current_swing]
local load = animator:LoadAnimation(anim)
load.Priority = Enum.AnimationPriority.Action4
load:Play()
local data = {char = character, swing = current_swing, action = "slash"}
remote:FireServer(data)
slash(character, current_swing)
current_swing = current_swing + 1
task.wait(1)
character.Humanoid.WalkSpeed = 16
character.Humanoid.JumpHeight = 7.2
cooldown = false
end
end)
swingAnims = {
'rbxassetid://11414802020', --1
'rbxassetid://11414802020', --2
'rbxassetid://11414802020', --3
'rbxassetid://11414802020', --4
'rbxassetid://11414802020', --5
}
local tween_service = game:GetService("TweenService")
local replicated_storage = game:GetService("ReplicatedStorage")
local uis = game:GetService("UserInputService")
local resources = replicated_storage:WaitForChild("Weapons"):WaitForChild("Katana"):WaitForChild("Default")
local fx = resources:WaitForChild("Fx")
local remote = replicated_storage:WaitForChild("Remotes"):WaitForChild("Combat")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local root_part = character:WaitForChild("HumanoidRootPart")
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local current_swing = 1
local cooldown = false
local anim = script:WaitForChild("Animation")
local function slash(character, swing)
end
uis.InputBegan:Connect(function(input, gpe)
if gpe then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 and cooldown == false and character:FindFirstChild("Stun") == nil then
if current_swing > 4 then
current_swing = 1
end
cooldown = true
print("should play animation now")
anim.AnimationId = swingAnims[current_swing]
local loadedanim = humanoid:LoadAnimation(anim)
loadedanim.Priority = Enum.AnimationPriority.Action
loadedanim:Play()
print("anim played sucessfully")
local data = {char = character, swing = current_swing, action = "slash"}
remote:FireServer(data)
slash(character, current_swing)
current_swing = current_swing + 1
task.wait(1)
character.Humanoid.WalkSpeed = 16
character.Humanoid.JumpHeight = 7.2
cooldown = false
end
end)