Pressure plate script not working

Hi I am new to the DevFourm and I am working on a game. the point is that when you step on and in visible plate the portal disappears. Any ideas on how I can fix this script? (i am new so be honest is there are dumb mistake or this is in the wrong category )

script:

local portal = script.Parent.portal
local plate = script.Parent[“Pressure plate”]
local walls = script.Parent.wall
local doc = script.Parent[“Dr. James Calimari”]

local function onTouch
if otherPart.Name ~= “Terrian”
walls.wall1.CanCollide = false
walls.wall2.CanCollide = false
walls.wall3.CanCollide = false
portal.Part.Transparency = 1
doc.Transparency = 1

end

end
plate.Touched:Connect(onTouch)

3 Likes

i meant “on an invisible plate”

2 Likes

There are quite a few issues with your script.
Here’s a model I made of a swinging door with an OnTouch plate that may enlighten you.
You can remove the hinge, Anchor your door Parts and make sure you name the variables properly.

2 Likes

ill try like I said I’m new and don’t know much but I’m learning

2 Likes

ty Scottifly

1 Like

This will always be useful.

1 Like

this could work. I added the connection variable so that it only works once. I don’t know if that’s what you expect

local portal = script.Parent.portal
local plate = script.Parent["Pressure plate"]
local walls = script.Parent.wall
local doc = script.Parent["Dr. James Calimari"]

local connection

local function onTouch (otherPart)
	if otherPart.Name ~= "Terrian" then
		connection:Disconnect()
		walls.wall1.CanCollide = false
		walls.wall2.CanCollide = false
		walls.wall3.CanCollide = false
		portal.Part.Transparency = 1
		doc.Transparency = 1
	end
end

connection = plate.Touched:Connect(onTouch)

in the explorer you should have something like this
image

1 Like

ty :+1: :+1: :+1: :+1: :+1: :+1: :+1:

1 Like

it doesn’t work and i don’t know why

Please post this in the right catagory #help-and-feedback:scripting-support

1 Like

There are many errors here. First of all, your not calling “otherPart”, which will give you a nil value. You also don’t have brackets on the local function onTouch, which you need. You also don’t have “then” after your if statement. Try this and see if it works:

local portal = script.Parent.portal
local plate = script.Parent[“Pressure plate”]
local walls = script.Parent.wall
local doc = script.Parent[“Dr. James Calimari”]

local function OnTouch(Hit)
if Hit.Parent:FindFirstChild(“Humanoid”) then
walls.wall1.CanCollide = false
walls.wall2.CanCollide = false
walls.wall3.CanCollide = false
portal.Part.Transparency = 1
doc.Transparency = 1
end
end

plate.Touched:Connect(OnTouch)

Let me know if that helps!

nope doesn’t. let me send a picture of my workspace mybe that will help find the problem

image

Dr James calimari is a character

Your model should look like this. Inside of the character is all of the character parts.
Screenshot_45

Along with that, the script should look like this:

local portal = script.Parent.Portal.Portal
local plate = script.Parent:WaitForChild(“Pressure Plate”)
local walls = script.Parent.Walls
local doc = script.Parent:WaitForChild(“Dr. James Calimari”)

local function OnTouch(Hit)
if Hit.Parent:FindFirstChild(“Humanoid”) then
walls.Wall1.CanCollide = false
walls.Wall2.CanCollide = false
walls.Wall3.CanCollide = false
portal.Transparency = 1

	for i,v in pairs(doc:GetChildren()) do
		if v:IsA("BasePart") then
			v.Transparency = 1
		end
	end
end

end

plate.Touched:Connect(OnTouch)

Hope this works! :slight_smile:

Oh ok. Btw would it still work if instead of script.parent.___ would it work as workspace. .

Indeed, you’d just have to go through the model and find all of the parts. I just find it easier to use script.Parent.

I noticed the then thing i totall6 missed that

Oh ok thx :+1: :+1: :+1: :+1: :+1::+1:

I 2ill try this tomarrow ill let u know if it works