Playing animation if character is touching

I am making a bush that is supposed to play a blowing animation when it is not being touched, but is supposed to shake if someone is touching it.

I have tried to get this to work, but I must be doing something wrong. The problem is that it keeps playing the animation over and over so quickly that it actually looks like it’s not even playing it. Here is what I have tried.

	-- Check how many parts are touching and play appropriate animation
	local TouchingParts = rig.TouchBox:GetTouchingParts()
	local CanDo = true
	
	while true do
		if CanDo == true then
			if #TouchingParts == 0 then
				-- Play blow animation
				CanDo = false
				BlowAnimationTrack:Play()
			else
				-- Play ShakeLight animation
				CanDo = false
				ShakeLightAnimationTrack:Play()
			end
			wait()
		end
	end

If you could help, I would appreciate it!

2 Likes