How would I make this part rotate when pressing an in game button or Key

Hello,
I am wanting to make a theme park ride system where you hold a key on the keyboard or press a button in game and the ride vehicle will start rotating up. When you release the button after about 2 seconds I wan’t the part to rotate back to its original rotation. How would I do this?

I have attached a video example of the ride I would like to make!

Jeremy Jet - Thomas Land Drayton Manor - YouTube

Thanks :slight_smile:

You would use TweenService to accomplish this.

1 Like

Hey,
Sorry I should of made it more in detail. I know I need to use TweenService but how would I make it so when I press a button or a key the Tween would Tween the part for how long as the button / key is pressed.
Cheers

---local script inside  of starterplayerscripts  might be  buggy sometimes
--click on  part you want to rotate
local player = game.Players.LocalPlayer
local part
local mouse = player:GetMouse()
local userinputservice = game:GetService("UserInputService")

mouse.Button1Down:Connect(function()
	part  = mouse.Target
	
userinputservice.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.R then
		print("Key pressed")
		part.Orientation =  part.Orientation + Vector3.new(0,45,0)---"R" rotates sideways
		print("Worked")
		end
	end)
end)

userinputservice.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.T then
		print("Key pressed")
		part.Rotation =  part.Rotation + Vector3.new(45,0,0)---"T" rotates Up
		print("Worked")
	end
end)

Sorry it took me a while hope you like it1! :smiley:

Hey,

Sorry for late reply. I may need to carry this on in about 1 week when I am home and can try it out properly. Do you know how to make it so however long the player holds down a key / press a button it rotating until they take the key off.
Thank you for the help though. Really appreciate it.

Thanks :slight_smile:

Oh I dont know but this dev forum made me make a game where you select parts and just mess with them kinda like sandbox game lol