Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to turn a block's collision on after clicking another block?

I am new to scripting, I started learning this week.

I have a block that has a click detector, which has the following script in it. I want to click a block, and then have three doors turn on their collision and also turn off their transparency (meaning it is visible to the player now). I don't even know if the script knows which blocks to change -

script.Parent.MouseClick:Connect(function ()
	game.Workspace("Red Door"):Connect(function ()
		script.Parent.CanCollide = true
		wait(0)
		script.Parent.Transparency = 0
		wait(0)
	game.Workspace("Green Door"):Connect(function ()
		script.Parent.CanCollide = true
		wait(0)
		script.Parent.Transparency = 0
		wait(0)
	game.Workspace("Blue Door"):Connect(function()
		script.Parent.CanCollide = true
		wait(0)
		script.Parent.Transparency = 0
		wait(0)
			
		end)	
	end)
end)

end)

2 answers

✓ Accepted answer

Do this instead.

script.Parent.MouseClick:Connect(function()
	game.Workspace["Red Door"].CanCollide = true
	game.Workspace["Red Door"].Transparency = 0
	game.Workspace["Green Door"].CanCollide = true
	game.Workspace["Green Door"].Transparency = 0
	game.Workspace["Blue Door"].CanCollide = true
	game.Workspace["Blue Door"].Transparency = 0
end)

7 comments

0

Doesn't work - I looked at the developer console and it said that the Red Door is not a valid member of Workspace and there is an error with Line 2

0

then you do not have the doors in the workspace, in order to fix this you must move your red, green, and blue doors into the workspace or change the pathing in the code to go to wherever they are. Ex. if they were inside of a model called "House" which was located in the workspace you would do game.Workspace.House["Red Door"].CanCollide = true

0

If you did the last part instead of moving the doors into the workspace then you would have to correct the directory on lines 2-7

0

I double checked and all three of the blocks are in the workspace. Is there any other possible error I could have encountered?

0

make sure the doors are anchored

0

WAIT A MINUTE ANCHORING IT ACTUALLY WORKED LMAO

0

can you accept this as an answer pls

Its better if you have local variables in your script lemme give you an example

local part1 = game.Workspace.Part1
local part2 = game.Workspace.Part2
local part3 = game.Workspace.Part3
local part4 = game.Workspace.Part3

part1.ClickDetector.MouseClick:Connect(function()
	part1.CanCollide = true
	if part1.CanCollide == true then -- Add an if statement to do the rest.
		part2.CanCollide = true
		part2.Transparency = 0
		part3.CanCollide = true
		part3.Transparency = 0
		part4.CanCollide = true
		part4.Transparency = 0
	end		
end	 

Make sure your parts/doors is set to CanCollide = false

This discussion is preserved as it was. New answers, comments, and votes are closed.