Busted CFrame on my door

I’m trying to make a door tween open using this code:

local TweenService = game:GetService("TweenService")
local door = script.Parent
local doorHinge = door.PrimaryPart
local doorOpen = TweenInfo.new()

local doorCFrame = TweenService:Create(doorHinge, doorOpen, {
	CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(-100),0)
})

local doorCFrameClosed TweenService:Create(doorHinge, doorOpen, {
	CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(0), 0)
})

local ClickDetection = script.Parent.ClickDoor.ClickDetector

ClickDetection.MouseClick:Connect(function()
	doorCFrame:Play()
	ClickDetection.MaxActivationDistance = 0
	script.Parent.Open:Play()
	wait(3)
	doorCFrameClosed:Play()
	ClickDetection.MaxActivationDistance = 24
	wait(1)
	script.Parent.Close:Play()
	
end)

When I run the script, the door noise plays but the door does not open, and the output logs me this error “Workspace.Door.Script:21: attempt to index nil with ‘Play’”
Looking at the actual script, where I write doorHinge.CFrame, it doesn’t seem to be registering CFrame as a property that I can edit, I don’t know how to fix this, all help is appreciated!

-Thanks, thekingorespawn

can u show script, where this error script at
Workspace.Door.Script:21

if my lua box isnt working than the script is

local TweenService = game:GetService(“TweenService”)

local door = script.Parent

local doorHinge = door.PrimaryPart

local doorOpen = TweenInfo.new()

local doorCFrame = TweenService:Create(doorHinge, doorOpen, {

CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(-100),0)

})

local doorCFrameClosed TweenService:Create(doorHinge, doorOpen, {

CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(0), 0)

})

local ClickDetection = script.Parent.ClickDoor.ClickDetector

ClickDetection.MouseClick:Connect(function()

doorCFrame:Play()

ClickDetection.MaxActivationDistance = 0

script.Parent.Open:Play()

wait(3)

doorCFrameClosed:Play()

ClickDetection.MaxActivationDistance = 24

wait(1)

script.Parent.Close:Play()

end)

I think you missed =

local doorCFrameClosed = TweenService:Create(doorHinge, doorOpen, {

CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(0), 0)

})

When creating a variable, remember to use the = symbol to signify you are assigning a value!

In this part of your code, you forgot to put the = symbol between doorCFrameClosed and the value.


Some side note improvements you can do as well:

  • Make more variables, such as for the sounds, and for script.Parent.ClickDoor
  • Properly utilize door. I noticed you had that variable but still had cases like script.Parent.ClickDoor.ClickDetector
  • Add a debounce system so people can’t spam-click the door to break it.

I have updated my code to look like this

local TweenService = game:GetService(“TweenService”)

local door = script.Parent

local doorHinge = door.PrimaryPart

local doorOpen = TweenInfo.new()

local doorCFrame = TweenService:Create(doorHinge, doorOpen, {

CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(-100),0)

})

local doorCFrameClosed = TweenService:Create(doorHinge, doorOpen, {

CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(0), 0)

})

local ClickDetection = door.ClickDetector

ClickDetection.MouseClick:Connect(function()

ClickDetection.MaxActivationDistance = 0

doorCFrame:Play()

door.Open:Play()

wait(3)

doorCFrameClosed:Play()

wait(1)

door.Close:Play()

ClickDetection.MaxActivationDistance = 24

end)

Now when I run the script in game there is no error in the output, the sound and sequencing work fine, as well as the click stopper, however the door itself doesnt move and i cannot pass through

For future reference, please format your code so that it is readable.

Is there other code manipulating the door?

1 Like

Not that I know of, also how do I format code without opening a new tab starting a thread copy-pasting the example lua block and coming back.

Put three ` marks, then the code, then another three.

Alright, if it helps anymore I’ve recorded a video of what is happening,

local door = script.Parent
local doorHinge = door.PrimaryPart
local doorOpen = TweenInfo.new()

local doorCFrame = TweenService:Create(doorHinge, doorOpen, {
	CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(-100),0)
})

local doorCFrameClosed = TweenService:Create(doorHinge, doorOpen, {
	CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(0), 0)
})

local ClickDetection = door.ClickDetector

ClickDetection.MouseClick:Connect(function()
	ClickDetection.MaxActivationDistance = 0
	doorCFrame:Play()
	door.Open:Play()
	wait(3)
	doorCFrameClosed:Play()
	wait(1)
	door.Close:Play()
	ClickDetection.MaxActivationDistance = 24
	
end)```
Here is the script I am using, If this helps anything more than that's great.

It’s because you didn’t provide the basic values in the TweenInfo.new(). Here is an example:

TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)

And the working code:

local TweenService = game:GetService("TweenService")
local door = script.Parent
local doorHinge = door.Parent.PrimaryPart
local doorOpen = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)

local doorCFrame = TweenService:Create(doorHinge, doorOpen, {
	CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(-100),0)
})

local doorCFrameClosed = TweenService:Create(doorHinge, doorOpen, {
	CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(0), 0)
})

local ClickDetection = door.ClickDetector

ClickDetection.MouseClick:Connect(function()
	ClickDetection.MaxActivationDistance = 0
	doorCFrame:Play()
	door.Open:Play()
	wait(3)
	doorCFrameClosed:Play()
	wait(1)
	door.Close:Play()
	ClickDetection.MaxActivationDistance = 24
end)

Also you could probably replace hinge with a pivot point instead but that’s optional and it’s just a tip from me.

This is a step in the right direction, although now the sound no longer works and it supplies me with this error at the doorCFrame on line 7 and I’d assume the doorCFrameClose variable too.
Workspace.Door.Script:7: attempt to index nil with ‘CFrame’ - Server - Script:7

Was about say he could used tweeninfo to out slide or open his doors.

I am sorry I had changed your code a bit for testing. Here is the fix.

local TweenService = game:GetService("TweenService")

local door = script.Parent
local doorHinge = door.PrimaryPart
local doorOpen = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)

local doorCFrame = TweenService:Create(doorHinge, doorOpen, {
	CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(-100),0)
})

local doorCFrameClosed = TweenService:Create(doorHinge, doorOpen, {
	CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(0), 0)
})

local ClickDetection = door.ClickDetector

ClickDetection.MouseClick:Connect(function()
	ClickDetection.MaxActivationDistance = 0
	doorCFrame:Play()
	door.Open:Play()
	wait(3)
	doorCFrameClosed:Play()
	wait(1)
	door.Close:Play()
	ClickDetection.MaxActivationDistance = 24
end)

This solved the issue with the sound although the door still doesn’t tween any, it also isn’t logging any errors in the output box.

Is the door anchored? If yes then unanchor it. If it moves out of its place then weld it with the hinge part.

1 Like

Activate.SoundID = should fix the sounding when the door is opened