Animation playing again when I don't want to

Hello! I want to make it such that when a player clicked on the screen or the mouse when the tool is equipped, the character will play an animation. Currently, in this script, the animation played out perfectly. However, I don’t want the animation to play from the beginning again when the player clicked on the screen and the previous animation haven’t finished playing. I tried using debounce as shown in this code below but it still doesn’t work. Is there anyway I can solve this issue?

local rice = script.Parent
local animation = rice.Animation
local hasstart = true
rice.Activated:Connect(function()
	local character = rice.Parent
	if character:WaitForChild("Humanoid") and hasstart == true then
		print("true")
		hasstart = false
		print("false")
		local lefthand = character:WaitForChild("LeftHand")
		local spoon = game.ReplicatedStorage.Spoon:Clone()
		spoon.Parent = character
		local newcframe = CFrame.new(0.482,-0.322,0.081)
		local cframeangle = CFrame.Angles(math.rad(-2.541), math.rad(-94.529), math.rad(88.645))
		local positioncframe = lefthand.CFrame * newcframe
		spoon.CFrame = positioncframe * cframeangle
		local weld = Instance.new("Weld")
		weld.Part0 = lefthand
		weld.Part1 = spoon
		weld.C0 = lefthand.CFrame:Inverse()
		weld.C1 = spoon.CFrame:Inverse()
		weld.Parent = lefthand
		local humanoid = rice.Parent:WaitForChild("Humanoid")
		local track = humanoid:LoadAnimation(animation)
		track:Play()
		track.Stopped:Connect(function()
			spoon:Destroy()
			hasstart = true
			print("true")
		end)
	end
end)


Was the animation looped or is it’s priority not set to action? Also, you should use Humanoid.AnimationController when running animations as Humanoid:LoadAnimation() is deprecated.

1 Like

Try checking if the Animation has looped set to true, if it is, make it false.

You need to check the animation status before deciding whether to play it again, or let the previous one finish, so:

if not track.IsPlaying then
	track:Play()
end

it is set to action already so that the animation can be played

how can I check it? Is it found in Roblox Studio?

How can I use the AnimationController?

Use the Animation Editor and look for the animation from the NPC. Look for it and set it to false.

I deleted that NPC… do I need to redo the animation?

Well obviously yes… You need the animation save in the NPC or it’s gone

oh well thanks for telling me about that

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