I am making a fighting game, and this script is not loading correctly…
This is a script for an animation
local player = game:GetService(“Players”).LocalPlayer
local character = player.Character
local animation = script.Parent:FindFirstChild(“Animation”)
local swinganimation = character.Humanoid:LoadAnimation (animation)
local canSwing = true
local debounce = 1
script.Parent.Activated:Connect(function()
if canSwing then
canSwing = false
swinganimation:play()
wait(debounce)
canSwing = true
end
end)
local player = game:GetService(“Players”).LocalPlayer
local character = player.Character
local animation = script.Parent:FindFirstChild(“Animation”)
local swinganimation = character.Humanoid:LoadAnimation(animation)
local canSwing = true
local debounce = 1
script.Parent.Activated:Connect(function()
if canSwing then
canSwing = false
swinganimation:Play()
wait(debounce)
canSwing = true
end
end)
The Character and the Humanoid don’t load in instantly, they have to load in.
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChild("Humanoid") or Character:WaitForChild("Humanoid")
local Tool = script.Parent
local Animation = Tool:FindFirstChild("Animation") or Tool:WaitForChild("Animation")
local SwingTrack = Humanoid:LoadAnimation(Animation)
local Debounce = false
local Cooldown = 1 -- The higher the number the longer the player has to wait before using the tool again
Tool.Activated:Connect(function()
if not Debounce then
Debounce = true
SwingTrack.Priority = Enum.AnimationPriority.Action -- A higher priority will override an animation of a lower priority
SwingTrack:Play()
wait(Cooldown)
Debounce = false
end
end)