Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a model rotate when a part is clicked?

Asked by 8 years ago

I'm trying to make a chair for The Voice, a TV show and was trying to make a chair when I got confused over the coding. Would it be something like this?

1if local.Button pressed then rotate local.Chair (0.1)
2wait (0.1)
3repeat (900)
4end
1
You need to at least learn Lua syntax. cabbler 1942 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

Insert a ClickDetector into the part that you are using as a chair. Then use a function to register the click of the player. You then need to call that function with the MouseClick event.

1local clickDetector = Instance.new("ClickDetector", part)
2 
3local function onMouseClick(player)
4    --Doesn't do anything, yet
5end
6 
7clickDetector.MouseClick:connect(onMouseClick)

To slowly change the rotation of an object, I prefer to use a HingeConstraint. (Note, of course, that the PGS Physics Solver must be enabled.) Attach one attachment to the chair, another to the floor, and put a HingeConstraint to connect them. Turn the ActuatorType of the HingeConstraint to Servo and mess with the settings until you get what you want. Then turn the Enabled property to off. Then put code into the function to turn on the HingeConstraint.

1local clickDetector = part.ClickDetector
2local hinge = part.HingeConstraint
3 
4local function onMouseClick(player)
5    hinge.Enabled = true
6end
7 
8clickDetector.MouseClick:connect(onMouseClick)
Ad

Answer this question