I am trying to make a bush that will shake when you walk through it.
The issue is that, when I walk through it, it will play the shake animation more times than I want it to. Here is a video.
I have tried figuring this out, but can’t.
Here is my code. As far as I can tell, it seems to always be counting CanPlay as true, so it plays the animation for every body part that touches.
local CanPlay = rig:GetAttribute('CanPlay')
-- Fire Touched function when touched
rig.TouchBox.Touched:Connect(function(part)
if CanPlay then
if part.Parent:FindFirstChild("Humanoid") then
rig:SetAttribute("CanPlay", false)
ShakeAnimationTrack:Play()
rig.Rustle:Play()
wait(0.5)
end
end
end)