How can I use tweens to make this bounce animation?

I’m trying to make a bounce animation that plays after this hat finishes flying in the air so I made a local script for the tween and then in one of the server scripts after the hat finishes flying I have a :fireclient() which plays the tween and then in the server script I have a seciton where if the player touches the hat it puts the hat back on their head and so I have another :fireclient() but this time to cancel the tween

there are 2 issues I noticed it’s probably because of the way I coded it tho, but:

  1. The tween doesn’t play the first time the hat finishes flying
  2. Sometimes while the hat is going up and down it randomly starts going all crazy

so how do you like properly use tween do this?

2 Likes

Can I see your code? 30 characters

You can use the Enum.EasingStyle.Bounce.

I would like to see some code first.

This is the code I have in the local script it’s just code from a tutorial as I never really used tweens before so don’t know how to use them

local tweenPlay = game.ReplicatedStorage:WaitForChild("TweenPlay")
local tweenStop = game.ReplicatedStorage:WaitForChild("TweenStop")
tweenPlay.OnClientEvent:Connect(function(player)
	local TweenService = game:GetService("TweenService")
	local part = game.Workspace:WaitForChild(player.Name.."'s Hat")
	local currentPos = part.CFrame
	local Info = TweenInfo.new(
		
		2, --Length
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		100, --Times Repeated (is there a way to repeat this forever?)
		true, --Reverse
		0 --Delay	
	)
	
	local Goals = 
	{
		Position = Vector3.new(currentPos.X, currentPos.Y-3, currentPos.Z)
	}
	
	local test = TweenService:Create(part, Info, Goals)
	test:Play()
	tweenStop.OnClientEvent:Connect(function(player)
		test:Cancel()
	end)
end)

As for the server scripts I can’t really send the entire code, but I just use this at different parts when I wanna play or stop the tween :I

tweenPlay:FireClient() and tweenStop:FireClient()

To repeal forever, use this:

local Info = TweenInfo,new(
2,
Enum.EasingStyle.Bounce,
Enum.EasingDirection.Out,
-1,
true,
0
)

Basically, any number less than one means forever. Also, like I mentioned earlier, use Enum.EasingStyle.Bounce for a bouncy efffect.

1 Like

Hmm the tween is still glitchy Animated GIF - Find & Share on GIPHY also I have a part inside the hat with the forcefield material, but for some reason the tween doesn’t effect that even though it’s welded to the hat so I had to make a second script, but for the shield.