I want to know what script is needed for a button to make a door go to its target angle, specifically using a button to activate a script something like this
local door = doorModel.Door
local clickDetector = door.ClickDetector
local pivot = doorModel.Pivot
local hinge = pivot.HingeConstraint
local open = false
clickDetector.MouseClick:Connect(function()
open = not open
local targetAngle = open and 90 or 0
hinge.TargetAngle = targetAngle
end)
I think that using a HingeConstraint is not needed. What is pivot? The primary part of the model to rotate? Just use that, change the CFrame angle of that part, you could do it with specific orientation angle and with open/close debounce.
Just make sure all the parts of the door are welded to the Pivot part, and not anchored or wont move:
A basic door example: aDoor.rbxm (5.4 KB)
local Pivot = script.Parent:WaitForChild("Pivot")
local BTN = script.Parent:WaitForChild("BTN"):WaitForChild("ClickDetector")
local Open = false
local OpenAngle = -80
local ClosedAngle = 0
BTN.MouseClick:Connect(function(player)
warn(player, "clicked the door")
if not Open then
Open = true
Pivot.CFrame = CFrame.new(Pivot.Position) * CFrame.Angles(math.rad(0), math.rad(OpenAngle), math.rad(0))
else
Open = false
Pivot.CFrame = CFrame.new(Pivot.Position) * CFrame.Angles(math.rad(0), math.rad(ClosedAngle), math.rad(0))
end
end)
it works but the orientation is weird, also I want to make the door opening to be smooth and if I were to guess, Tweenservice is put somewhere in the script, right?
Yup, that script works for the door I sent, due to how the model is built, your model is different than mine. You just need to change stuff in the script or in your model. (I was only showing you how you could do it)
Yup, if you want it to be smooth, you could use TweenService or chaging the orientation with a loop or RunService beat