LoadedAnim not stopped in a seperate function

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

tool system where pressing 1 causes to equip playing wield anim, then pressing while equipped
causes unequip, stopping anim

  1. What is the issue? Include screenshots / videos if possible!

anim not stopping after :Stop(0) (the code runs without errors)

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

i found some similar posts but the solutions to all of them were that
their loadedanim variables (if they had one at all) were changed before stopping, so they would stop an entirely new anim but i dont see that here

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

serverscript code below, event fired from localscript when 1 is pressed
also i tried stopping it like this:

loadedanim:Play(0) -- played here
task.wait(1)
loadedanim:Stop(0)

and that worked so it must be something wrong with it being stopped in that function
sorry if youve seen the solution to this somewhere i couldnt find anything else

local backpack = script.Parent.Parent
local eqanim = script.Equip
local loadedanim
local function unequiptool(tool)
	
	loadedanim:Stop(0) -- no errors; loadedanim not nil
	
	print("unequipping"..tool.Name) -- runs ; above code also runs
	
	tool.Parent = backpack
end
local function equiptool(plr:Player, toolname:string)
	local char = plr.Character or plr.CharacterAdded:Wait()
	local animator = char:WaitForChild("Humanoid"):WaitForChild("Animator")
	
	print("changing variable") -- only prints when i equip
	loadedanim = animator:LoadAnimation(eqanim)
	
	if not backpack:FindFirstChild(toolname) then unequiptool(char[toolname]) return end
	local tool = backpack[toolname]
	local handle = tool:FindFirstChild("Handle") or tool
	local rightgrip = tool.RightGrip:Clone()
	local rightarm = char['Right Arm']
	
	rightgrip.Part0 = rightarm
	rightgrip.Part1 = handle
	rightgrip.Parent = rightarm
	tool.Parent = char
	
	loadedanim:Play(0) -- played here


end
script.Parent.EquipReq.OnServerEvent:Connect(equiptool)

ok turns out the output was lying to me and it was infact printing twice (the remote event was fired by pressing 1, which happens when you want to unequip, playing the original function and changing the variable before stopping)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.