Hello!
Take a look at this video where I am clicking on the Rummage Button and it explodes into tiny pieces and falls to the bottom.
As you can see the animation is a bit clunky and not smooth. I want to make it satisfying to click on.
I hope you get the general idea.
Code: LocalScript
newButton.Position = UDim2.new(randomX, 0, randomY, 0)
newButton.Parent = RumageFrame
newButton.Visible = true
newButton.MouseButton1Click:Connect(function()
TrashSound:Play()
newButton.Visible = false
local piecesCount = math.random(20,25)
for i=1, piecesCount do
local piece = Instance.new("Frame") -- Replace with ImageLabel if you want images
piece.Size = UDim2.new(math.random(0.01, 0.07), 3, math.random(0.01, 0.07), 3)
piece.Position = UDim2.new(newButton.Position.X.Scale, 0, newButton.Position.Y.Scale, 0) -- Start at button's position
piece.BackgroundColor3 = Color3.new(0,0,0) -- Random color
piece.Parent = RumageFrame
local tween = game:GetService("TweenService"):Create(
piece,
TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out),
{
Position = UDim2.new(
newButton.Position.X.Scale + math.random(-5, 5) / 100, -- Small random scale offset
10, -- No offset in X
newButton.Position.Y.Scale + math.random(-5, 5) / 100, -- Small random scale offset
10 -- No offset in Y
)
}
)
tween:Play()
tween.Completed:Connect(function()
local fallTween = game:GetService("TweenService"):Create(
piece,
TweenInfo.new(0.5, Enum.EasingStyle.Linear),
{Position = UDim2.new(piece.Position.X.Scale, piece.Position.X.Offset, 1, math.random(0, 100))} -- Falling down
)
fallTween:Play()
fallTween.Completed:Connect(function()
piece:Destroy() -- Remove the piece
end)
end)
end
newButton:Destroy()
ShopBTNFrame.Visible = false
AdminBTNFrame.Visible = false
end)
newButton.Destroying:Wait()