Is there a way to create a constantly rotating a decal?

Hello people of the Devforum, I come today to ask all of you a question. How do you create a constantly rotating decal? I’ve seen it before but after some research I can’t seem to find any information on it.

Here is the decal I want to rotate
Screenshot_78
As you can see I added lines as sort of a way to show what direction I want it to go in

So what are some solutions to this? (Sorry im still learning about LUA and the basics)

2 Likes

Is that a gui or decal on a part?

1 Like

The thing I want to rotate is a decal on a Screen GUI.

1 Like

put a local script inside of the gui. insert the following script:

while wait() do -- you can also put a number inside of the () to change how often it rotates.

    script.Parent.Rotation = script.Parent.Rotation + 0.1 -- change this to how much you want it to rotate over time.

 end
2 Likes

Are you sure its a decal? I’m pretty sure you can’t even add a decal to a ScreenGUI let alone why you would want to use one. Your just better off using a ImageLabel and using the rotation property and some TweenService to make it rotate.

1 Like

I’m pretty sure he’s trying to say it’s an image gui.

My bad, I meant Image label. Sorry im used to building lol.

I’d rather use TweenService for smooth panning and spinning.

I just tested it here is my code, it runs smooth

While true do
    Wait()
    script.Parent.Rotation = script.Parent.Rotation + 0.1
end
local gui = script.Parent
local info = TweenInfo.new(
time, -- in seconds
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local goal = {
Rotation = 360
}
local tween = game:GetService("TweenService"):Create(gui, info, goal)
while wait(time) do
tween:Play()
end
local delay = 0.1
local degrees = 0.1
local rotate = true -- You can make this rely on something so it's not always rotating, eg only rotates when the user hovers over it
while rotate == true do
    wait(delay)
    script.Parent.Rotation = script.Parent.Rotation + degrees -- Replace the + with a - to make it go backwards
end

Very straightforward, can be changed to have different amounts of rotation or different delays. If you know code, you can also add in stuff like “if x == 1 then + degrees else if x == 2 then - degrees” to have it go back and forth as you please.

As others have suggested, tweening is a good option, however doing this is arguably shorter and at least for newer users easier to read and understand

2 Likes

I generally don’t use loops unless I really have to, so…
Recursion!

-- Proof of concept
local TweenService = game:GetService("TweenService");
local TweenInformation = TweenInfo.new(1,  -- Time it takes to complete. By default, this tween's easingStyle is Linear, so that's good.
	Enum.EasingStyle.Linear); -- define this so it's not on Sine.
local Image = script.Parent;

local function Tween()
	Image.Rotation = 0;
	local Create = TweenService:Create(Image,TweenInformation,{Rotation = 359.9}); -- Set to closest value before 0 to smooth the transition to 0 in the line above.
	Create.Completed:Connect(Tween); -- This function will call itself again when the tween is done
	Create:Play();
end

Tween();

proof of concept.rbxm (3.3 KB) QoTxPMDSsY

6 Likes