Hi, I’ve been having trouble with this bit of code I wrote trying to do a sword combo. I’ve looked other places but I must have been bad with wording while searching because I wasn’t figuring out an answer. I can’t figure out why exactly it is erroring when I try to load the animation, as my other animation scripts have the code to load animations written in the same way and they work fine. Thank you for taking the time to read and help me out!
It keeps erroring on line 8
local character = game:GetService("Players").LocalPlayer.Character
local tool = script.Parent
local swordSlashOne = tool:WaitForChild("SwordSlash1")
local swordSlashTwo = tool:WaitForChild("SwordSlash2")
local swordSlashThree = tool:WaitForChild("SwordSlash3")
local swordSlashOneTrack = character.Humanoid:LoadAnimation(swordSlashOne)
local swordSlashTwoTrack = character.Humanoid:LoadAnimation(swordSlashTwo)
local swordSlashThreeTrack = character.Humanoid:LoadAnimation(swordSlashThree)
local swordCombo = 0
local nextActivate = os.clock()
local debounceTime = 1
tool.Activated:Connect(function()
if os.clock() > nextActivate then
nextActivate = os.clock() + debounceTime
if swordCombo == 0 then
swordCombo = 1
swordSlashOneTrack:Play()
elseif swordCombo == 1 then
swordCombo = 2
swordSlashTwoTrack:Play()
elseif swordCombo == 2 then
swordCombo = 0
swordSlashThreeTrack:Play()
end
end
end)
I’m sorry, I am rather new to scripting and am not understanding how to do that correctly. I tried a few different ways to possibly use that correctly just now and I must not be understanding the correct use of WaitForChild or something. Could you elaborate?
--//Services
local Players = game:GetService("Players")
--//Variables
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local tool = script.Parent
local swordSlashOne = tool:WaitForChild("SwordSlash1")
local swordSlashTwo = tool:WaitForChild("SwordSlash2")
local swordSlashThree = tool:WaitForChild("SwordSlash3")
local swordSlashOneTrack = Humanoid:LoadAnimation(swordSlashOne)
local swordSlashTwoTrack = Humanoid:LoadAnimation(swordSlashTwo)
local swordSlashThreeTrack = Humanoid:LoadAnimation(swordSlashThree)
--//Controls
local swordCombo = 0
local nextActivate = os.clock()
local debounceTime = 1
--//Functions
tool.Activated:Connect(function()
if os.clock() > nextActivate then
nextActivate = os.clock() + debounceTime
if swordCombo == 0 then
swordCombo = 1
swordSlashOneTrack:Play()
elseif swordCombo == 1 then
swordCombo = 2
swordSlashTwoTrack:Play()
elseif swordCombo == 2 then
swordCombo = 0
swordSlashThreeTrack:Play()
end
end
end)