Hello! I am wondering how I can make my parts rotate and move when a button is clicked. I’ve looked all over YouTube and couldn’t really find anything helpful and with my very minimal knowledge about scripting I don’t really have any idea where to start. All I need is a simple turn as shown below, any help would be very much appreciated!
I suggest using TweenService, a service that allows you to interpolate properties of an Instance, such as a Part’s orientation. Such a Tween would look like this:
local part = script.Parent
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
1, --Duration in seconds
Enum.EasingStyle.Linear, --EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
0, -- RepeatCount (when less than zero the tween will loop indefinitely)
false, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime in seconds
)
local tweenGoal = {Rotation = --[[new orientation of your choosing]]}
local tween = tweenService:Create(part,tweenInfo,tweenGoal)
tween:Play()
You could then put this code block under a ClickDetector’s MouseClick
event.
local part = script.Parent
local clickDetector = part.ClickDetector
clickDetector.MouseClick:Connect(function()
--Create and play tween
end)