Scripting help (For hinge to rotate only 1 way)

Hello,

I’ve made a spinning door, so I would like to make it rotate right only with force to avoid rotating other way and slowly spinning.

b47816625bbf3790f8365bc334c0c681b2bd4c31_2_405x500

So, as you see a spinning door. Green arrow is where I want it to rotate and red arrow is where I don’t want it to rotate other way.

I’m using a Hinge, with none like Motor neither a Servo and no limits.

(I didn’t know that needed to script for rotating only 1 way, so I re-posted for this topic).

I think instead of the player pushing the door, it would be better to have the door rotate constantly, you could do this by tweening the door. If you want it to only work when a player is near, you could make an invisible part and put it over the door, ensure Can Collide is false, and when a player is touching the part start the tween until they leave.

This is what your code could look like, feel free to edit any of the parameters to see what they do!

-- Defining variables and importing
local door = script.Parent -- Change to the correct directory
local TweenService = game:GetService("TweenService") -- Importing TweenService

-- Tween

local tweenInfo = TweenInfo.new(
	2, -- Time
	Enum.EasingStyle.Linear, -- EasingStyle
	Enum.EasingDirection.Out, -- EasingDirection
	-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
	false, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
)
	
local partProperties = {
	
	Orientation = Vector3.new(0,180,0) -- The end orientation
	
}

local tweenDoor = TweenService:Create(door, tweenInfo, partProperties) -- Creating the Tween
tweenDoor:Play() -- Play the tween

Like that is hard, I would prefer player pushing door.

You could put a part of the side of the door, in the direction that you don’t want it being pushed that anchors the door while the player is touching the part and anchors it when the player is not touching it.

Mhm, but how do I do force for it not to rotate wrong way?

Like, in real life if you force door to go back it might break or be dangerous. That is I want it to go only 1 way when player pushes it.

If you put the part on the right side of each pain of glass, not all the way through, so if a player touches it the door is anchored (Meaning it can’t move) but is anchored once the player stops pushing it. So if the player tries to push the door the wrong way then it gets anchored and the door doesn’t move but is anchored when they push it the correct way.

Oh, like that. How do I script them like that?

Something along the lines of the following:

-- Defining Variables

local door = game.Workspace.door
local stopper = door.stopper

-- Functions

local function onTouch(Hit)
      if Hit and Hit.Parent and Hit.Parent:FindFirstChildOfClass('Humanoid') then -- It is a player touching it
            door.Anchored = true -- Anchor the door
      end
end

stopper.Touched:Connect(onTouch) -- When touched run the onTouch function

local function endTouch(Hit)
       if Hit and Hit.Parent and Hit.Parent:FindFirstChildOfClass('Humanoid') then -- It is a player touching it
             door.Anchored = false -- Unanchor the door
       end
end

stopper.TouchEnded:Connect(endTouch) -- When touched run the endTouch function

This code is untested, however gives you the basics of how to approach this.

Not working, I have a model calling “Door spinning” and then parts “door” grouped in.

You need to set a part in your door to be the primary part and move it with that, change the variable directories to the one in your game, I can’t give you everything :slight_smile: just play around for a bit and you will get it to work and have gained some programming knowledge! Don’t worry about getting it wrong, you can always try again.

Oh yeah, this is a tough one. This is more of a physics and mechanisms question than a scripting one. In particular, what you’re looking to achieve here for your revolving door (more appropriate term for spinning door, to help your searches and such) is the braking mechanism which prevents opposite directional flow.

This can be accomplished in Studio if you’re relying solely on physics and the system is purely mechanical, but the difficult part is understanding how to do it. Not even I know how.

You may want to do some research on the braking mechanism for revolving doors to help you work towards potentially getting a solution. For example, you can look at the make of a revolving door and see what you can break down from it and incorporate to your own.

Yep, I see this is going to be hard as of learning. I’m still a noob (basic) scripting lol.

Sorry if im doing something wrong by bumping this, but I had the same issue and came up with a solution, so even though it wont help OP, im posting it so people who come across this thread with the same problem (like me) will be able to solve it without creating new threads.

The way I fixed it, was by inserting a hinged part that had limits enabled so that it could only turn ~50 degrees one way. This made it so that the turnstile could push the part out of the way when turning correctly, but would run into it when not. Here is an image of how it works.


In the image, you can see how at A, a Hinge and Torsion spring are setup. The hinge allows B to move out the way when pushed correctly by Parts A, however limits restrict it from being pushed the other way.

Also at A, there is a torsion spring which resets the position of B so that one push wont unlock it forever.

Hope this helps anyone with the same issue.

Edit: If any mods can move this to Physics / mechanics / building it would be more relevant there