Trying to make Balloons randomly float around inside a part

Okay this one works just fine, even moving the script to my game is perfect.

I think the last things I would wanna do is

  1. Have them randomly spawn in the box rather then all in the same spot. (I’m doing this right now and I might be able to do it by myself.)

  2. And maybe have it so I can just set an amount of balloons to spawn and the script will automatically do it without me having to repeat the same creation process each time.

1 Like

ok so for thing number 2 here’s the script:

local modeswitch = game.ReplicatedStorage.Gamemode.Value

if modeswitch == 2 then
	local LimitBox = script.Parent
	local BounariesX = LimitBox.Size.X
	local BounariesY = LimitBox.Size.Y
	local BounariesZ = LimitBox.Size.Z

	local Tweens = game:GetService("TweenService")
	local Cloud -- the cloud part, if the cloud is a model then you'd better off using runservice and :PivotTo()

	--Balloon Config

	--Balloon 1
	local Ballons = {}
	for i = 0, 10, 1 do --Edit the middle number for the amount of ballons you want
		local Balloon1 = Instance.new("Part")

		local boardgui = Instance.new("BillboardGui")
		boardgui.Size = UDim2.new(10,0,10,0)
		boardgui.Parent = Balloon1

		local spray = Instance.new("ImageLabel")
		spray.BackgroundTransparency = 1
		spray.Size = UDim2.new(1.25,0,1.25,0)
		local rng1 = math.random(1,4)
		if rng1 == 1 then
			spray.Image = 'http://www.roblox.com/asset/?id=18665545469' -- Blue Balloon
		elseif rng1 == 2 then
			spray.Image = 'http://www.roblox.com/asset/?id=18665545039' -- Green Balloon
		elseif rng1 == 3 then
			spray.Image = 'http://www.roblox.com/asset/?id=18665545173' -- Orange Balloon
		elseif rng1 == 4 then
			spray.Image = 'http://www.roblox.com/asset/?id=18665545294' -- Purple Balloon
		end
		spray.Parent = boardgui
		spray.ResampleMode = Enum.ResamplerMode.Pixelated

		Balloon1.Name = "Balloon1"
		Balloon1.Transparency = .5
		Balloon1.Color = Color3.new(1, 0, 0.0156863)
		Balloon1.Parent = workspace.BalloonArea
		Balloon1.Position = script.Parent.Position + Vector3.new(0,0,0)
		Balloon1.Size = Vector3.new(1, 1, 1)
		Balloon1.CanCollide = false
		Balloon1.Anchored = true
		table.insert(Ballons,Balloon1)
	end
	--"Animation" Tweening

	local function CloudTween()
		local tween = {}
		for i,v in Ballons do
			local twaan = Tweens:Create(v, TweenInfo.new(1, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {CFrame = LimitBox.CFrame + (LimitBox.CFrame.RightVector * math.random(-LimitBox.Size.X/2,LimitBox.Size.X/2)) + (LimitBox.CFrame.LookVector * math.random(-LimitBox.Size.Z/2,LimitBox.Size.Z/2))})
			twaan:Play()
			table.insert(tween,twaan)
		end
		
		return tween[1]
	end

	--repeat indefinitely
	local function PlayTween()
		local tween = CloudTween()
		tween.Completed:Connect(PlayTween)
	end
	PlayTween() --start the loop
end
2 Likes

basically

For i = 0, ??, 1 do -> add balloon to table -> to make tween cycle through table -> to get a single tween to restart loop (return tween[1])
1 Like

Oh wow thank you! I would’ve lost my mind trying to figure out that lmao. Only problem now is what I had going before for random spawn positions won’t work.

Before you sent that, I was dividing
the tween speed with 2 different rng values to get a random X and Z spawn. Which worked alright but I’m sure there is a better way to do it.

ya i think just simply doing

Balloon1.Position = (LimitBox.CFrame + (LimitBox.CFrame.RightVector * math.random(-LimitBox.Size.X/2,LimitBox.Size.X/2)) + (LimitBox.CFrame.LookVector * math.random(-LimitBox.Size.Z/2,LimitBox.Size.Z/2)).p 

would work best

1 Like

OK wow that’s perfect! Thank you so much for all the help. Is there any way I could contact you in the future for assistance, if thats okay?

I’m sure I can reuse this script for something else that is similar, but it would need a lot more tweaking that I’m not sure I’d be able to do on my own. I’d appreciate the help.

If not that’s fine, you’ve helped me more then enough already, thanks for tolerating me lol.

well u can message me on the forum if u need more help and gl!

1 Like

Awesome, thanks again for all the help! Have a nice rest of your day/night^^

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.