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 7 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?

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

1 answer

Log in to vote
1
Answered by 7 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.

local clickDetector = Instance.new("ClickDetector", part)

local function onMouseClick(player)
    --Doesn't do anything, yet
end

clickDetector.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.

local clickDetector = part.ClickDetector
local hinge = part.HingeConstraint

local function onMouseClick(player)
    hinge.Enabled = true
end

clickDetector.MouseClick:connect(onMouseClick)

Ad

Answer this question