[Solved] How I can make a Door that only open can "CanCollide" enable

Hi, I was working on some kind of game kit that fully scripted,
but that only one thing I want make the Door “CanCollide” enable when is “Opened”,
after “Closed” is should be “CanCollide” disable, because some mobile player may pump on it
and glitch.

Script

local TweenService = game:GetService("TweenService")

local hinge = script.Parent.Hinge
local prompt = script.Parent.Door.ProximityPrompt

local goalOpen = {}
goalOpen.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(120), 0)

local goalClose = {}
goalClose.CFrame = hinge.CFrame * CFrame.Angles(0, 0, 0)

local tweenInfo = TweenInfo.new(1)
local tweenOpen = TweenService:Create(hinge, tweenInfo, goalOpen)
local tweenClose = TweenService:Create(hinge, tweenInfo, goalClose)

prompt.Triggered:Connect(function()
	if prompt.ActionText == "Close" then
		tweenClose:Play()
		prompt.ActionText = "Open"
	else
		tweenOpen:Play()
		prompt.ActionText = "Close"
	end
end)

Can you try and rephrase that? I’m not quite getting what your problem is.

1 Like

Do you mean that , CanCollide = false when it’s opened, and Cancollide = true when its closed?

I’m really confused

If you want the CanCollide to change when it’s open versus closed, just do this:

local Door = script.Parent:WaitForChild("Door")
local Debounce = false
prompt.Triggered:Connect(function()
if not Debounce then
	Debounce = true
	if prompt.ActionText == "Close" then
		tweenClose:Play()
		Door.CanCollide = false
		tweenClose.Completed:wait() -- Added so we're waiting for the door to fully close here, before we set Cancollide to true.
		Door.CanCollide = true
		prompt.ActionText = "Open"
	else
		tweenOpen:Play()
		Door.CanCollide = false
		tweenOpen.Completed:wait()
		Door.CanCollide = true
		prompt.ActionText = "Close"
	end
	Debounce = false
end
end)

I mean when I press “E” to open the Door I should be not pushing the character.

My script will work then. Go take a look at it. :slight_smile:

Edit of Edit: Nevermind, try my code now. :slight_smile: This will do so when the door is moving, it won’t push players. That is both when closing and opening.

Sorry about that, I tried it won’t work. :disappointed_relieved:

I updated my script since you pasted it in.

Edit: A basic principal you can easily get. :smiley:

CanCollide = true (the object is solid)
CanCollide = false (the object is not solid, and can be walked through)

It work but can’t close back.
But still a good solution! thank.

Ooh a misspelling of mine, Look in your “else” statement

		tweenOpen:Play()
		Door.CanCollide = false
		tweenClose.Completed:wait() -- This was set to Close
		Door.CanCollide = true
		prompt.ActionText = "Close"

should be

		tweenOpen:Play()
		Door.CanCollide = false
		tweenOpen.Completed:wait() -- Changed Close to Open
		Door.CanCollide = true
		prompt.ActionText = "Close"