I am creating a piggy like game and needed a knife. So, I began scripting. The problem is with the animations. They are different in-game than in the animation editor. Here are some videos:
-- the animation editor
robloxapp-20211006-2256583.wmv (325.7 KB)
-- the actual game
robloxapp-20211006-2258516.wmv (403.8 KB)
My Script (Server script in the tool):
local tool = script.Parent
local debounce = false
local debonceWait = 1
local animations = {
slash = script:WaitForChild("Slash"),
idle = script:WaitForChild("Idle"),
}
local loadedIdle
local loadedSlash
local humanoid
local function equip()
print("Equip")
if not humanoid then
humanoid = tool.Parent:WaitForChild("Humanoid")
end
if not loadedIdle then
loadedIdle = humanoid:LoadAnimation(animations.idle)
loadedIdle.Priority = Enum.AnimationPriority.Action
end
loadedIdle:Play()
end
local function unEquip()
print("UnEquip")
if loadedIdle then
loadedIdle:Stop()
end
end
local function slash()
if not debounce then
debounce = true
print("Slash")
if humanoid then
if not loadedSlash then
loadedSlash = humanoid:LoadAnimation(animations.slash)
loadedSlash.Priority = Enum.AnimationPriority.Action
end
end
loadedSlash:Play()
wait(debonceWait)
debounce = false
end
end
tool.Activated:Connect(slash)
tool.Unequipped:Connect(unEquip)
tool.Equipped:Connect(equip)