Sliding Door that's pressure plate and proximity prompt activated problem

I recently attempted to make a sliding door script enabled by a proximity prompt. The door is only supposed to open when there’s a mesh called “object” touching a part called “oppen”

The door does not seem to be opening when the object is touching the part and the prox promt is triggered by the player. The script does not produce any errors in the output for some reason

I have three main questions:

  1. How do i fix this problem?

  2. Whats causing this problem?

  3. How can i avoid this problem with other scripts?

Heres the script for the Door with comments

speed = 0.30

door1 = script.Parent.SlidingDoor1
door2 = script.Parent.SlidingDoor2
prompt = script.Parent.Parent.ProxP.ProximityPrompt
oppen = script.Parent.Oppen


--Main Script Starts Here
prompt.Triggered:Connect(function(player)
	prompt.Enabled = false
	

	--Detects weather the "object" is touching the part named "oppen"
	oppen.Touched:Connect(function(Hit)
		if Hit.Name == "Object" then


			--This loop moves the two doors away from each other 
			--so the player can pass through
			for i=1,(door1.Size.z/speed) + 1 do
				wait()
				door1.CFrame = door1.CFrame - (door1.CFrame.lookVector * speed)
				door2.CFrame = door2.CFrame - (door2.CFrame.lookVector * speed)
			end
			prompt.Enabled = false	
			
			
		end
	end)
end)

if you have any questions about the script feel free to ask!

Many Thanks
-FastTheDev

If you are saying your problem is that it’s not detecting the name “object” it might be because it is Capital.
I would also remove the “oppen” Touched event since you are making a new event every time someone triggers the prompt which is not good for performance.

Hello, I think that Firstly, it seems like the .Touched event is being used inside the .Triggered event. This means that the .Touched event will only be listened for after the ProximityPrompt is triggered. This might not be what you want if the “object” is already touching the “oppen” part when the prompt is triggered by the player.

In addition, in your for loop, you’re moving both doors in the same direction. Usually, when creating a sliding door, you’d want the doors to move in opposite directions. Therefore, one should be subtracted from and the other should be added to.

speed = 0.30

door1 = script.Parent.SlidingDoor1
door2 = script.Parent.SlidingDoor2
prompt = script.Parent.Parent.ProxP.ProximityPrompt
oppen = script.Parent.Oppen
objectTouching = false

--Detects whether the "object" is touching the part named "oppen"
oppen.Touched:Connect(function(Hit)
	if Hit.Name == "Object" then
		objectTouching = true
	end
end)

oppen.TouchEnded:Connect(function(Hit)
	if Hit.Name == "Object" then
		objectTouching = false
	end
end)

--Main Script Starts Here
prompt.Triggered:Connect(function(player)
	if objectTouching then
		prompt.Enabled = false

		--This loop moves the two doors away from each other 
		--so the player can pass through
		for i=1,(door1.Size.z/speed) + 1 do
			wait()
			door1.CFrame = door1.CFrame - (door1.CFrame.lookVector * speed)
			door2.CFrame = door2.CFrame + (door2.CFrame.lookVector * speed)
		end
		prompt.Enabled = true
	end
end)

Thank you, however one of the doors is already rotated in the opposite direction i believe, which is why when i tested the raw door moving script by its self the doors moved in the correct directions.

I have one important question about this solution: will it sacrifice performance for functionality? (will it make the game laggier or slower? as i already have a large map)

I just double checked and the name of the object is “Object” with an uppercase O. How would i remove the touched event without destroying the whole script?

The change made to your script shouldn’t significantly impact performance. The ‘.Touched’ and ‘.TouchEnded’ events will only fire when the specific conditions are met - i.e. when the “object” begins or ceases to touch the “oppen” part. This isn’t a constant check but something that happens in response to these specific events, so it shouldn’t contribute much to the overall load on your game.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.