local knife = script.Parent
local aimAnimation = knife:WaitForChild("PrepareThrow")
local player = game.Players.LocalPlayer
knife.Activated:connect(function()
local s,e = pcall(function()
local loaded_aimAnimation = player.Character.Humanoid:LoadAnimation(aimAnimation)
loaded_aimAnimation:Play()
loaded_aimAnimation:GetMarkerReachedSignal("Charge"):connect(function(parameter)
print(parameter)
end)
loaded_aimAnimation:GetMarkerReachedSignal("PauseAnimation"):connect(function()
print("pause")
end)
end)
The script was based off of a youtube video but I wrapped the code in a pcall and still didn’t get an error. The animation does play but it doesnt pause like it’s supposed to.
Hi there, if you’re still having trouble, I have a few suggestions:
I’m not sure if it’ll make much of a difference, but try to use “:Connect” from now on rather than “:connect” as the latter is technically deprecated.
Don’t wrap code in pcall if you’re trying to figure out what’s wrong with it. Pcall will hide your errors rather than reveal them.
There’s no need to load the same animation multiple times, especially if it’s the same person using the tool. You could go further and check to see if it’s the same person using it, but below you’ll see a modified version that should at least help a bit.
local knife = script.Parent
local aimAnimation = knife:WaitForChild("PrepareThrow")
local player = game.Players.LocalPlayer
local loaded_aimAnimation
local activationConnection
knife.Equipped:Connect(function()
loaded_aimAnimation = player.Character.Humanoid:LoadAnimation(aimAnimation)
local function onActivated()
loaded_aimAnimation:Play()
loaded_aimAnimation:GetMarkerReachedSignal("Charge"):Connect(function(parameter)
print(parameter)
end)
loaded_aimAnimation:GetMarkerReachedSignal("PauseAnimation"):Connect(function()
print("pause")
end)
end
activationConnect = knife.Activated:Connect(onActivated)
end)
knife.Unequipped:Connect(function()
if activationConnection then
activationConneciont:Disconnect()
loaded_aimAnimation = nil
end
end)