How do I make the door open when the ball touches object

How would I make it so that when the ball highlighted is touching the pressure plate the door tweens up and opens?

If you need more explaination tell me in the comments and i’ll try answer any questions


https://gyazo.com/82021c5037ca8e936a6bcef1b4bc41e9

3 Likes

You need to use a Touched event on the pressure plate or the ball. See if the touched object is the ball / pressure plate. If it is than play a tween using tween service to open the door.

This is the code I used, its not working

local ball = game.Workspace.ball
local plate = game.Workspace.plate
local door = game.Workspace[“Door puzzle”]

if plate.Touched:Connect(function(platet)
if ball then
door.Transparency = true
door.CanCollide = false
end
end)

also how do i join up the code blocks?
I am not used to devforum

Try using this
local Trigger = script.Parent

local function onPartTouched(otherPart)

--Insert the rest of the script here.

end

Trigger.Touched:Connect(onPartTouched)

Make sure that the Trigger part is not touching anithing else

Say if hit.Parent:FindFirstChild("ball name") then your code instead of saying if ball then .

So like this:

local plate = game.Workspace.plate
local door = game.Workspace:WaitForChild(“Door Puzzle”)

if plate.Touched:Connect(function(platet)
if hit.Parent:FindFirstChild(“ball”) then
door.Transparency = true
door.CanCollide = false
end
end)

Thanks, I’ll try it!
[character limit]

1 Like

Oops my bad if you were to do this you need to say if platet.Parent:FindFirstChild("ball") then because your parameter is platet.

i was just abt to say something was wrong lol

Again I’ll try and see if it works!

1 Like

Nope, can you try format the text completely since I need things directly laid out to understand

local trigger = game.Workspace.plate

local function onPartTouched(otherPart)
local ball = game.Workspace.ball
local plate = game.Workspace.plate
local door = game.Workspace.Doorpuzzle

if platet.Parent:FindFirstChild("ball") then
		if hit.Parent:FindFirstChild(game.Workspace.ball) then
			door.Transparency = true
			door.CanCollide = false
		end
	end

    trigger.Touched:Connect(onPartTouched)

Can you try correct that code but have the complete code there?

Yea there is a lot of things wrong with this. I created my own simulation in a new template with a script you can use. Here it is:

local trigger = game.Workspace.Part

local function ontouched(hit)
	local door = game.Workspace.Door
	if hit.Parent:FindFirstChild("Ball") then
		door.Transparency = 0.5
		door.CanCollide = false
	end
end

trigger.Touched:Connect(ontouched)

I hope you can understand this and use it in your game. If you have any other issues, please let me know.

where do I put this script? In the pad the ball touches?

That would actually be best. You should just make the trigger the script’s parent. Some things might also not be what you intended so you might need to change up some names. Well I hope this helps.

Oh my lord, thank you! I’ve been trying to script this for days before going to devforum about it!

2 Likes