Door Script doesn't work

Hello!
I was doing a door for my game but I got stuck on the script I made. I’d need help to see what’s the problem.

Images of the door

So, I basically looked up on YT multiple tutorials to see my error but I can’t seem to find it.
For some information please message it down below. Also, the lighter part’s of the door is a mesh, do I need to change it too?

Thanks in advance for the help! :smiley:

1 Like

I cannot help you unless I know what the door is meant to do, how it is supposed to work and what the error / problem is. Can you also paste your current script in here?

1 Like

Sure! I’ll show you the script.

"local Hinge = script.Parent.PrimaryPart
local opened = false

function OpenDoor()
if opened == false then
opened = true
for i = 1, 21 do
script.Parent:SetPrimaryPartCFrame(Hinge.CFrameCFrame.Angles(0, math.rad(5), 0))
wait()
end
else
opened = false
for i = 1, 21 do
script.Parent:SetPrimaryPartCFrame(Hinge.CFrame
CFrame.Angles(0, math.rad(-5), 0))
wait()
end
end
end

script.Parent.Handle1.ClickDetector.MouseClick:Connect(OpenDoor)
script.Parent.Handle2.ClickDetector.MouseClick:Connect(OpenDoor)"

Also, it’s meant to be the opening and closing door of a house.

Try this, local Wood = true

local parent = script.Parent

local function on()
Wood = true
parent.Transparency = 0
parent.CanCollide = true
end

local function off()
Wood = false
parent.Transparency = 0.8
parent.CanCollide = false
end

local function OnClicked()
if Wood == true then off() else on() end

end
parent.ClickDetector.MouseClick:connect(OnClicked)

on()
You do need a click detector though.

I’ll try it. Also, the handles each got a ClickDetector.

And how could I make it close too?

The script I gave will close the door if you click again on it.

Alright!
Where should I put the script?
I made a model with the door parts and another with the frame. Do I put it in the Door Model or in the main part of it?

Just put it on the door model! and you should be done!

Hey man, I highly suggest using TweenService, CFraming doors like these with this method can cause a LOT of lag on the serverside if you end up having a lot, it causes issues with performance.
I highly suggest considering this alternative as it is more performance-friendly and way smooth

2 Likes

Wait actually put it like this actually!

okay so you have to put it on like the main door part i guess?

Could you give me an example, it’d help me alot to get one. I’m some type of visual man.

Here you go!

There is the same script on that door!

You can search Youtube for “sliding door TweenService tutorial roblox”.
They are endless and provide source code.

Well, mine is not a sliding door. But I’ll go check it out to make sure!

Thanks by the way!

1 Like

You didnt multiply the quaternions and also you didnt supply a number for i

How much should I multiply it?

No I mean you didnt supply a operator, you just did hinge.CFrameCFrame.Angles()

How should I do it then?
Here’s a screenshot to edit or just tell what to do.!