local ProximityPrompt = script.Parent:WaitForChild("ProximityPrompt") -- Assuming the ProximityPrompt is a child of the door
local opened = false
local Sound = script.Parent:WaitForChild("Sound") -- Assuming the sound is a child of the door
-- Ensure the PrimaryPart is set
script.Parent.PrimaryPart = script.Parent:WaitForChild("DoorPart") -- Replace "DoorPart" with the actual part you want to rotate (e.g., the door's main part)
-- Function to open and close the door
local function ToggleDoor()
if opened == false then
opened = true
Sound:Play()
for i = 1, 21 do
-- Rotate the door around its PrimaryPart (assuming the part you've set as PrimaryPart is the hinge point)
script.Parent:SetPrimaryPartCFrame(script.Parent.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(4.6), 0))
wait()
end
else
opened = false
Sound:Play()
for i = 1, 21 do
-- Rotate the door back to its original position
script.Parent:SetPrimaryPartCFrame(script.Parent.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(-4.6), 0))
wait()
end
end
end
-- Connect the ProximityPrompt's action to toggle the door
ProximityPrompt.Triggered:Connect(function(player)
ToggleDoor()
end)
based on the comments it looks like you’ve had an ai write it? dont expect everything that ai makes is going to work
Anyways i dont have a lot of time right now but ill look at the script once i do
Click on your model and go to properties menu and find property called PrimaryPart click on that and then you go to the main part of the door and click on it and you should see that property became smth like: Primary Part : (PartName)
You have to do some Hinge calculations, like get the Position of the PrimaryPart, Add a Vector3 to the X Axis. This vector will be the negative of the position of the PrimaryPart divided by 2, Add a Rotation with CFrame Angles on the Y Axis, this will be used to rotate the door around the hinge.
local hingeOffset = Vector3.new(-script.Parent.PrimaryPart.Size.X / 2, 0, 0)
local hingePoint = script.Parent.PrimaryPart.Position
-- inside the function:
local rotation = CFrame.Angles(0, math.rad(4.6), 0)
local offset = script.Parent.PrimaryPart.CFrame:pointToObjectSpace(hingePoint)
script.Parent:SetPrimaryPartCFrame(CFrame.new(hingePoint) * rotation * * CFrame.new(-offset))