Old roblox model respawn selectionbox effect

This effect used to be around players and models when you spawn them. Does anyone know how I could replicate this for models when I regenerate them?

4 Likes

Which part of the selectionbox do you need help with?

2 Likes

How do I make it cycle through the rainbow and can I even toggle it on and off with a script

2 Likes

It looks like this would be done using a tween. You can use a tween to cycle through two color values. The two color values might be

Color3.fromHSV(0,1,1) and Color3.fromHSV(1,1,1) and that should cover in a rainbow.

1 Like

To toggle it on:

function ToggleSelectionBox(Model)
for i, v in pairs(Model:GetDescendants()) do
if v:IsA('BasePart') then
local SelectionBox = instance.new('SelectionBox')
SelectionBox.Parent = v
end
end
end

to toggle it off:

function ToggleSelectionBoxOff(Model)
for i, v in pairs(Model:GetDescendants()) do
if v:IsA('SelectionBox') then
v:Destroy()
end
end
end

Then to change the colors:

local t = 5; --how long does it take to go through the rainbow

while wait() do
	local hue = tick() % t / t
	local color = Color3.fromHSV(hue, 1, 1)
	--> set the color
end

do something like that ^
Code is taken from here: How to create a simple rainbow effect using TweenService - Resources / Community Resources - Roblox Developer Forum

1 Like

Alternatively you could do tweenservice which would make the animation a lot smoother and not use while wait().

local TweenService = game:GetService("TweenService")
local tinfo = TweenInfo.new(5, Enum.EasingStyle.Linear)

local part = game.Workspace.Part -- let's just say this is a ref to your part
part.Color = Color3.fromHSV(0,1,1)

local goal = {}
goal.Color = Color3.fromHSV(1,1,1)

local tween = TweenService:Create(part, tinfo, goal)
tween:Play()

This should make a tween which cycles through all of the hues on the part without having to use a while wait() loop, which can have adverse effects. A while wait() loop can significantly slow down if the server is having problems, and it won’t be as smooth as a tween anyway.

I might add that this example is only for a part’s color. However, it shouldn’t be hard to modify it to a SelectionBox object.

Yeah i know, i just gave him a rough idea of how to go about doing it.
I was assuming OP knew about tweening so i just copy pasted the first code i saw

@SanctuaryIX

ok, so a few problems
I get an error called unable to cast dictionary on
local tween = TweenService:Create(SelectionBox, tinfo, goal)

local function ToggleSelectionBox(Vehicle)
	for i, v in pairs(Vehicle.BodyKit:GetDescendants()) do
		if v:IsA('BasePart') then
			local SelectionBox = Instance.new('SelectionBox')
			SelectionBox.Parent = v
			SelectionBox.Adornee = v
			while wait(5) do
				local TweenService = game:GetService("TweenService")
				local tinfo = TweenInfo.new(5, Enum.EasingStyle.Linear)
				SelectionBox.Color = BrickColor.Random()
				local goal = {}
				goal = BrickColor.Random()
				local tween = TweenService:Create(SelectionBox, tinfo, goal)
				tween:Play()
			end
		end
	end
end
function ToggleSelectionBoxOff(Vehicle)
	for i, v in pairs(Vehicle.BodyKit:GetDescendants()) do
		if v:IsA('SelectionBox') then
			v:Destroy()
		end
	end
end

The tween doesn’t tween to another color, it just waits the duration then flips to another color, but this might be because of the error
also only a single part has a selection box
image

1 Like

You would need to make seperate threads for each individual part in the loop so it would not stop the main thread(script)

local function ToggleSelectionBox(Vehicle)
	for i, v in pairs(Vehicle.BodyKit:GetDescendants()) do
		if v:IsA('BasePart') then
			local SelectionBox = Instance.new('SelectionBox')
			SelectionBox.Parent = v
			SelectionBox.Adornee = v
            spawn(function()
  			 while wait(5) do
				local TweenService = game:GetService("TweenService")
				local tinfo = TweenInfo.new(5, Enum.EasingStyle.Linear)
				SelectionBox.Color = BrickColor.Random()
				local goal = {}
				goal = BrickColor.Random()
				local tween = TweenService:Create(SelectionBox, tinfo, goal)
				tween:Play()
			 end
           end)
		end
	end
end

You cannot tween a part’s BrickColor instead you tween the part’s Color so it can tween the color values, brick color does not have that but its Color.

local TweenService = game:GetService("TweenService")
local tinfo = TweenInfo.new(5, Enum.EasingStyle.Linear)
SelectionBox.Color = BrickColor.Random().Color-- you have to get the BrickColor's Color property if u are trying to assign a color to a basepart's Color property
local goal = {Color = BrickColor.Random().Color} -- just set the goal already in the table
local tween = TweenService:Create(SelectionBox, tinfo, goal)
tween:Play()

local goal = {}
goal = BrickColor.Random()

This should be

goal.BrickColor = BrickColor.Random()

however, you should be using Color3.FromRGB / FromHSV to tween the color instead of brickcolors.

goal.Color3 = Color3.FromHSV(math.random(0, 100) / 100,1,1)

1 Like

You can also get the Color values from BrickColors too
BrickColor.new(“whatuname”).Color
same applies with .Random()

I might also add that it does not need to be in a while wait(5) loop. The tinfo has a property which can make it loop forever.

2 Likes


also the toggleselectionboxoff() never is called so the selection boxes never turn off. to combat this i did
local goal = {Color = BrickColor.Random().Color, ToggleSelectionBoxOff(Vehicle)} but nothing happens and there are no errors

1 Like

Change the selectionbox’s Color to SurfaceColor3

I’ll make a quick example and send it. There is also an issue of the tween not doing anything because it thinks it’s already at the goal color.

nuh uh
image

edit: ok fine

1 Like

{Color3=BrickColor.Random().Color}

ok pog doing what i was told worked and there no no errors anymore @SanctuaryIX and the goal thing happens so the selection boxes turn off

but how do i make it change color like in the video, currently it goes from one shade of blue to another, but i want to make it loop between blue and red (and purple because purple wants to fit in)

1 Like

Here is an example model which will tween:

TweenModel.rbxm (3.8 KB)

If you wish to use it for selection boxes, pass the selectionbox as the part and use
goal.SurfaceColor3 instead of goal.Color

you assign chosen colors in a table

local colorlist = {
Color3.new(1,0,0),--Red
Color3.new(0,0,1)--Blue
}
local index = 1
local function ToggleSelectionBox(Vehicle)
	for i, v in pairs(Vehicle.BodyKit:GetDescendants()) do
		if v:IsA('BasePart') then
			local SelectionBox = Instance.new('SelectionBox')
			SelectionBox.Parent = v
			SelectionBox.Adornee = v
            spawn(function()
  			 while wait(5) do
				local TweenService = game:GetService("TweenService")
				local tinfo = TweenInfo.new(5, Enum.EasingStyle.Linear)
				SelectionBox.Color = Color3.new(0,0,1)
				local goal = {Color = colorlist[index]}
				local tween = TweenService:Create(SelectionBox, tinfo, goal)
				tween:Play()
                if index==#colorlist then index=1 else index+=1 end
			 end
           end)
		end
	end
end