Trying to make Balloons randomly float around inside a part

So basically, I’m trying to make a script that’ll spawn 4 balloon parts that will randomly float around on the X and Z exist (So only around the room, not up and down) AND stay inside the bounding box that the balloon parts will be parented to. But I can’t exactly figure out how to go about it. I’ve tried a few different scripts but nothings worked. Tweening has always been an issue for me.

Here’s the script I’m using currently along with the “file” structure too.

local RandX = LimitBox.CFrame * CFrame.new(math.random(-LimitBox.Size.X/2, LimitBox.Size.X/2),math.random(-LimitBox.Size.Y/2, LimitBox.Size.Y/2),math.random(-LimitBox.Size.Z/2, LimitBox.Size.Z/2))
local RandZ = LimitBox.CFrame * CFrame.new(math.random(-LimitBox.Size.Z/2, LimitBox.Size.Z/2),math.random(-LimitBox.Size.Y/2, LimitBox.Size.Y/2),math.random(-LimitBox.Size.Z/2, LimitBox.Size.Z/2))

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()

local Balloon = Instance.new("Part")

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

local spray = Instance.new("ImageLabel")
spray.BackgroundTransparency = 1
spray.Size = UDim2.new(1.25,0,1.25,0)
spray.Image = 'http://www.roblox.com/asset/?id=18665545294'
spray.Parent = boardgui
spray.ResampleMode = Enum.ResamplerMode.Pixelated

Balloon.Name = "Balloon"
Balloon.Transparency = .5
Balloon.Color = Color3.new(1, 0, 0.0156863)
Balloon.Parent = workspace.BalloonArea
Balloon.Position = script.Parent.Position + Vector3.new(0,0,0)
Balloon.Size = Vector3.new(1, 1, 1)

local function CloudTween()
	local tween = Tweens:Create(Balloon, TweenInfo.new(50, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {CFrame = CFrame.new(Balloon.Position.X - LimitBox.CFrame.X, 10, Balloon.Position.Z - LimitBox.CFrame.Z)})
	tween:Play()
	return tween
end

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

image

4 Likes

Can u replace:

CFrame = CFrame.new(Balloon.Position.X - LimitBox.CFrame.X, 10, Balloon.Position.Z - LimitBox.CFrame.Z)

with:

CFrame = CFrame.new(LimitBox.CFrame.X, 10, LimitBox.CFrame.Z)

and see what happens

3 Likes

You should just get boundaries, so like X, Y and Z axis, limits for both ways
they you can spawn part randomly inside the part, making sure it spawns inside the part, you can do that by taking lower boundary from each axis (lets say its all 5) and then you substract that from upper boundaries (lets say they are 15, so results for each axis would be 10), then you just need to pick random number from 0 to result (which was 10) and then add this random number to the lower boundary (lets say you got 2.5, 5, and 7.5 as random numbers, you add them to axis, and you have result 7.5, 10, 12.5 which is inside boundaries)
And you could use similar checks for tweening, you just choose which direction you want to move first, then you check how far you are able to move by substracting your position from appropriate boundary, generate random number and add it to current position.

3 Likes


Unless I Put it in incorrectly (Which is highly likely), This doesn’t work.

3 Likes

lol ya you did

Also can u show where u declared LimitBox?
Also ignore the random B i typed in there

2 Likes

Trying what you sent definitely did something, The Balloon will now float up and down a little bit. Which honestly works, but now it doesn’t seem to be moving on the X or Z axis.

image

2 Likes

I think mabye it could have something to do with the boxes orientation? If not I think ill remake the script my own way

2 Likes

It should be orientated correctly? I tried rotating it and matching the directions but it just yields the same result…

1 Like

Try this line:

local tween = Tweens:Create(Balloon, TweenInfo.new(50, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {CFrame = CFrame.new(LimitBox.CFrame.X + LimitBox.CFrame.LookVector.X * math.random(-LimitBox.Size.X/2,LimitBox.Size.X/2), 10, LimitBox.CFrame.Z + LimitBox.CFrame.LookVector.Z * math.random(-LimitBox.Size.Z/2,LimitBox.Size.Z/2))})

instead of:

local tween = Tweens:Create(Balloon, TweenInfo.new(50, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {CFrame = CFrame.new(Balloon.Position.X - LimitBox.CFrame.X, 10, Balloon.Position.Z - LimitBox.CFrame.Z)})

Just test and see what that does

i got this (i just sped up the tween speed to see the effects faster)

robloxapp-20240726-2211571.wmv (1.5 MB)

1 Like

Works alright when set to a proper speed but its prone to flipping out and possibly destroying itself

1 Like

I think it could the be bounce effect try turn it off to see if its the issue?

1 Like

Changing it to linear just has it destroy itself (for some reason???) once it reaches the end of its tween, and if it doesn’t: It just teleports back to the center instead of going from where it was to somewhere else.

1 Like

(I have no idea why something so simple is taking so long to figure out and dont ask why the x and z are the wrong way around it for some reason just works like that)

local function CloudTween()
	local X = LimitBox.CFrame.Z + LimitBox.CFrame.LookVector.X * math.random(-LimitBox.Size.X/2,LimitBox.Size.X/2)
	local Z = LimitBox.CFrame.X + LimitBox.CFrame.RightVector.Z * math.random(-LimitBox.Size.Z/2,LimitBox.Size.Z/2)
	local tween = Tweens:Create(Balloon, TweenInfo.new(1, Enum.EasingStyle.Bounce), {CFrame = CFrame.new(Z, 10, X)})
	tween:Play()
	return tween
end

if this effect is all perfect and not broken and just fast then replace ClowdTween with this above

robloxapp-20240726-2246286.wmv (91.0 KB)

1 Like

Using this, I got the 4 balloons to spawn and get randomly assigned a color. But now they only seem to move on the Y and Z Axis’s and not the X Axis. (This script is calling for gamemode detection so you’ll have to cut that part out for it to work for you)

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 rng1 = math.random(1,4)
local rng2 = math.random(1,4)
local rng3 = math.random(1,4)
local rng4 = math.random(1,4)

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 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)
	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

--Balloon 2

local Balloon2 = Instance.new("Part")

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

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

Balloon2.Name = "Balloon2"
Balloon2.Transparency = .5
Balloon2.Color = Color3.new(1, 0, 0.0156863)
Balloon2.Parent = workspace.BalloonArea
Balloon2.Position = script.Parent.Position + Vector3.new(0,0,0)
Balloon2.Size = Vector3.new(1, 1, 1)
Balloon2.CanCollide = false
Balloon2.Anchored = true

--Balloon 3

local Balloon3 = Instance.new("Part")

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

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

Balloon3.Name = "Balloon3"
Balloon3.Transparency = .5
Balloon3.Color = Color3.new(1, 0, 0.0156863)
Balloon3.Parent = workspace.BalloonArea
Balloon3.Position = script.Parent.Position + Vector3.new(0,0,0)
Balloon3.Size = Vector3.new(1, 1, 1)
Balloon3.CanCollide = false
Balloon3.Anchored = true

--Balloon 4

local Balloon4 = Instance.new("Part")

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

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

Balloon4.Name = "Balloon4"
Balloon4.Transparency = .5
Balloon4.Color = Color3.new(1, 0, 0.0156863)
Balloon4.Parent = workspace.BalloonArea
Balloon4.Position = script.Parent.Position + Vector3.new(0,0,0)
Balloon4.Size = Vector3.new(1, 1, 1)
Balloon4.CanCollide = false
Balloon4.Anchored = true

--"Animation" Tweening

local function CloudTween()
	local tween = Tweens:Create(Balloon1, TweenInfo.new(30, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {CFrame = CFrame.new(LimitBox.CFrame.X + LimitBox.CFrame.LookVector.X * math.random(-LimitBox.Size.X/2,LimitBox.Size.X/2), 10, LimitBox.CFrame.Z + LimitBox.CFrame.LookVector.Z * math.random(-LimitBox.Size.Z/2,LimitBox.Size.Z/2))})
	local tween2 = Tweens:Create(Balloon2, TweenInfo.new(30, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {CFrame = CFrame.new(LimitBox.CFrame.X + LimitBox.CFrame.LookVector.X * math.random(-LimitBox.Size.X/4,LimitBox.Size.X/6), 10, LimitBox.CFrame.Z + LimitBox.CFrame.LookVector.Z * math.random(-LimitBox.Size.Z/4,LimitBox.Size.Z/6))})
	local tween3 = Tweens:Create(Balloon3, TweenInfo.new(30, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {CFrame = CFrame.new(LimitBox.CFrame.X + LimitBox.CFrame.LookVector.X * math.random(-LimitBox.Size.X/6,LimitBox.Size.X/8), 10, LimitBox.CFrame.Z + LimitBox.CFrame.LookVector.Z * math.random(-LimitBox.Size.Z/6,LimitBox.Size.Z/8))})
	local tween4 = Tweens:Create(Balloon4, TweenInfo.new(30, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {CFrame = CFrame.new(LimitBox.CFrame.X + LimitBox.CFrame.LookVector.X * math.random(-LimitBox.Size.X/8,LimitBox.Size.X/4), 10, LimitBox.CFrame.Z + LimitBox.CFrame.LookVector.Z * math.random(-LimitBox.Size.Z/8,LimitBox.Size.Z/4))})
	tween:Play()
	tween2:Play()
	tween3:Play()
	tween4:Play()
	return
end

--repeat indefinitely
local function PlayTween()
	local tween = CloudTween()
	tween.Completed:Connect(PlayTween)
	local tween2 = CloudTween()
	tween2.Completed:Connect(PlayTween)
	local tween3 = CloudTween()
	tween3.Completed:Connect(PlayTween)
	local tween4 = CloudTween()
	tween4.Completed:Connect(PlayTween)
end
PlayTween() --start the loop
end
1 Like

Oh you seem to have forgoted about RightVector also i did a dumb and overcomplicated some parts of it so try this

local tween = Tweens:Create(Balloon1, 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))})
local tween2 = Tweens:Create(Balloon2, TweenInfo.new(1, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {CFrame = LimitBox.CFrame + (LimitBox.CFrame.RightVector * math.random(-LimitBox.Size.X/4,LimitBox.Size.X/6)) + (LimitBox.CFrame.LookVector * math.random(-LimitBox.Size.Z/4,LimitBox.Size.Z/6))})
local tween3 = Tweens:Create(Balloon3, TweenInfo.new(1, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {CFrame = LimitBox.CFrame + (LimitBox.CFrame.RightVector * math.random(-LimitBox.Size.X/6,LimitBox.Size.X/8)) + (LimitBox.CFrame.LookVector * math.random(-LimitBox.Size.Z/6,LimitBox.Size.Z/8))})
local tween4 = Tweens:Create(Balloon4, TweenInfo.new(1, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {CFrame = LimitBox.CFrame + (LimitBox.CFrame.RightVector * math.random(-LimitBox.Size.X/8,LimitBox.Size.X/4)) + (LimitBox.CFrame.LookVector * math.random(-LimitBox.Size.Z/8,LimitBox.Size.Z/4))})
tween:Play()
tween2:Play()
tween3:Play()
tween4:Play()
1 Like

I probably did something wrong, but now none of the balloons move after changing it to this.

local function CloudTween()
	local tween = Tweens:Create(Balloon1, 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))})
	local tween2 = Tweens:Create(Balloon2, TweenInfo.new(1, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {CFrame = LimitBox.CFrame + (LimitBox.CFrame.RightVector * math.random(-LimitBox.Size.X/4,LimitBox.Size.X/6)) + (LimitBox.CFrame.LookVector * math.random(-LimitBox.Size.Z/4,LimitBox.Size.Z/6))})
	local tween3 = Tweens:Create(Balloon3, TweenInfo.new(1, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {CFrame = LimitBox.CFrame + (LimitBox.CFrame.RightVector * math.random(-LimitBox.Size.X/6,LimitBox.Size.X/8)) + (LimitBox.CFrame.LookVector * math.random(-LimitBox.Size.Z/6,LimitBox.Size.Z/8))})
	local tween4 = Tweens:Create(Balloon4, TweenInfo.new(1, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {CFrame = LimitBox.CFrame + (LimitBox.CFrame.RightVector * math.random(-LimitBox.Size.X/8,LimitBox.Size.X/4)) + (LimitBox.CFrame.LookVector * math.random(-LimitBox.Size.Z/8,LimitBox.Size.Z/4))})
	tween:Play()
	tween2:Play()
	tween3:Play()
	tween4:Play()
	return
end
1 Like
local function CloudTween()
	local tween = Tweens:Create(Balloon1, 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))})
	local tween2 = Tweens:Create(Balloon2, TweenInfo.new(1, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {CFrame = LimitBox.CFrame + (LimitBox.CFrame.RightVector * math.random(-LimitBox.Size.X/4,LimitBox.Size.X/6)) + (LimitBox.CFrame.LookVector * math.random(-LimitBox.Size.Z/4,LimitBox.Size.Z/6))})
	local tween3 = Tweens:Create(Balloon3, TweenInfo.new(1, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {CFrame = LimitBox.CFrame + (LimitBox.CFrame.RightVector * math.random(-LimitBox.Size.X/6,LimitBox.Size.X/8)) + (LimitBox.CFrame.LookVector * math.random(-LimitBox.Size.Z/6,LimitBox.Size.Z/8))})
	local tween4 = Tweens:Create(Balloon4, TweenInfo.new(1, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {CFrame = LimitBox.CFrame + (LimitBox.CFrame.RightVector * math.random(-LimitBox.Size.X/8,LimitBox.Size.X/4)) + (LimitBox.CFrame.LookVector * math.random(-LimitBox.Size.Z/8,LimitBox.Size.Z/4))})
	tween:Play()
	tween2:Play()
	tween3:Play()
	tween4:Play()
	
	return tween
end

--repeat indefinitely
local function PlayTween()
	local tween = CloudTween()
	tween.Completed:Connect(PlayTween)
end

by the way are you not seeing any errors?

1 Like

this should have thrown an error this wasn’t returning anything at all

1 Like

Yeah no I haven’t been getting any errors. The one you just sent has them all spawned in 1 spot unmoving.

1 Like

i have no idea why its not like that for me soo look at this for your self and check if theres anything different in layout?

Tester - Roblox
(its uncopylocked btw)

1 Like