I’m looking for something like the rainbow pets in pet simulator and I don’t know where to start.
Please read the about page of this category.
Have you tried anything before making this post?
You’ll want to use some kind of loop to do this. While loops are great. Here’s a helpful article to explain loops: https://developer.roblox.com/articles/Roblox-Coding-Basics-Loops and one directly to while loops: https://developer.roblox.com/articles/Roblox-Coding-Basics-Loops#while
Inside of that loop you’ll want to change the brick color of the brick in question. Here’s the brickcolor api reference: http://wiki.roblox.com/index.php?title=BrickColor
So bricks have a property BrickColor which you can control with the BrickColor API listed above. If you combine your loop (with some sort of wait in it) you can make the the brick cycle through random brick colors (see
random in the BrickColor API reference: http://wiki.roblox.com/index.php?title=BrickColor#BrickColor.random)
I’m not sure what these rainbow pets do as I’ve never played that game or seen anything from it.
local brick = <TheBrickYouWantToRainbowColor> while wait(1) do brick.BrickColor = BrickColor.random() end
You can also check out this API to tween between different colors of the rainbow:
I personally think it could be a RGB loop (what the rainbow pets could do, i dont own any rainbow pet in any game)
local Brick = workspace.Brick --Change To Brick local speed = 1 --Change to speed you want while true do for i = 0,1,0.001*speed do Brick.Color = Color3.fromHSV(i,1,1) --creates a color using i wait() end end
Edit: since this reply has received quite a bit of traction I’ve decided to add a more modern method using RenderStepped.
Since it’s ran each frame and uses the step delta, it results in a much smoother rainbow cycle.
local RunService = game:GetService("RunService") local Brick = workspace:WaitForChild("Brick") --Change To Brick local SPEED = 0.1 --Change to speed you want local i = 0 RunService.RenderStepped:Connect(function(delta) Brick.Color = Color3.fromHSV(i,1,1) i = (i + delta*SPEED) % 1 end)
Can you unblur the code, that way we can copy the code
Why is it
while wait() do instead of
while true do? Won’t this make a quick pause every time the colors loop back around?
True, im just so used to writing while wait() do to stop it from freezing studio
Also there is no visible difference as it starts and ends in red
i know i’m a little late to the party here, but it’d probably be better if you changed it to
local speed = 5 while true do for i = 0,1,0.001*speed do script.Parent.Color = Color3.fromHSV(i,1,1) wait() end end
but i don’t script, so i may be wrong about this