How would I make items burst out of a chest?

So I’m making this game where you dig up chests that randomly spawn in random places at different intervals, and I already have everything setup in terms of the digging system and the animations. Now I’m at the point where I need to make the random item system, and I had a cool little thing planned out where the items fly/burst out of the chest onto the ground. It’s hard to explain since I couldn’t find any examples. I guess what I want to achieve is something like how the items come out of a Fortnite chest (if you know how that looks), since that’s the only similar example I can find. Please reply, because I would really like to know how to achieve this effect.

Chest opening animation:

1 Like

chest.wmv (302.3 KB)
something like this should hopefully help, tweak to your needs :slight_smile:

local ts = game:GetService("TweenService")
local ti = TweenInfo.new(0.45, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)

local chest = script.Parent

for i = 1,10 do
	local part = Instance.new("Part", workspace) -- replcae with your model or whatever
	part.Anchored = true
	
	part.Position = chest.Position
	coroutine.wrap(function()		
		local newLoc = part.Position + Vector3.new(math.random(-20,20), 0, math.random(-20,20))
		
		local tween = ts:Create(part, ti, {Position = newLoc + Vector3.new(0, 20 - (chest.Position - newLoc).Magnitude + 5, 0)})
		tween:Play()
		tween.Completed:Wait()
		tween:Destroy()
		
		local closestFallRaycast = workspace:Raycast(part.Position, Vector3.new(0, -1000, 0)) 
		if not closestFallRaycast then part:Destroy() return end
		
		tween = ts:Create(part, ti, {Position = closestFallRaycast.Position + Vector3.new(math.random(-2,2), 0, math.random(-2,2))})
		tween:Play()
		tween.Completed:Wait()
		tween:Destroy()
	end)()
end
2 Likes

Thank you so much!! I’ll try it out right now and let you know.

It works perfectly! Thank you so much!

1 Like

Here is the final product, if you’re curious:

3 Likes

The game is on a different account because I got devforum on here a while ago, and I don’t feel the need to apply to the devforum on there.

Looks good! :+1:


Sorry to bump, however if you would like a much smoother animation and your objects are unanchored consider using AssemblyLinearVelocity.

local part = Instance.new("Part", workspace)
part.Position = workspace.Emitter.Position + Vector3.new(0,2,0)
part.AssemblyLinearVelocity = Vector3.new(math.random(-30,30),100,math.random(-30,30))
part.CustomPhysicalProperties = PhysicalProperties.new(0, 1, 0, 1, 10)

Thank you! I’ll try this out.

lllllllllllllllllllllllllllll