I am trying to make if a player clicks on a block, another block would appear

I have started it but I don’t know how to continue.

local ClickDetector = Part:WaitForChild(“ClickDetector”)

ClickDetector.MouseClick:connect(function(Player)

(Sorry I am a beginner scripter)

Edit: I also need it when someone clicks it again, it changes it’s transparency.

I already have the part with the size, color, material and position. Is there a way that I can make it appear?

Here is the code:

local PartA = script.Parent
local PartB = game.Workspace.PartB
local ClickDetector = PartA:WaitForChild("ClickDetector")

ClickDetector.MouseClick:Connect(function(Player)
	PartB.Transparency = 0
else
	PartB.Transparency = 1
end)

Be sure to change the defined variables if necessary. This is one method of achieving your goal, so let me know if you face any difficulties.

Error; Expected ‘end’ (to close with function), got else.

Zenetsuku forgot an if statement , and a end statement

Sorry, please try this:

local PartA = script.Parent
local PartB = game.Workspace.PartB
local ClickDetector = PartA:WaitForChild("ClickDetector")
local Debounce = false

ClickDetector.MouseClick:Connect(function(Player)
	if not Debounce then
		Debounce = true
	PartB.Transparency = 0
else
	Debounce = false
	PartB.Transparency = 1
	end
end)

Sorry for the poor formatting in advance.

in fixture to Zenetsuku’s script

 if not Debounce then
     Debounce = true
     PartB.Transparency = 0
     PartB.CanCollide = true
else
    Debounce = false
    PartB.Transparency = 1
    CanCollide = false
end

local water = game.Workspace.bathtub.water

local ClickDetector = water:WaitForChild(“ClickDetector”)

local Debounce = false

ClickDetector.MouseClick:Connect(function(Player)

if not Debounce then

Debounce = true

water.Transparency = 0

else

Debounce = false

water.Transparency = 1

end

end)

Is there anything wrong in it? Because it doesn’t seem to really work for me.

What does not work specifically? May I see an image of how your workspace in roblox studio looks like? That would help a lot.

local PartA = script.Parent
local PartB = game.Workspace.PartB
local ClickDetector = PartA:WaitForChild("ClickDetector")
local Debounce = false

ClickDetector.MouseClick:Connect(function(Player)
	if not Debounce then
		Debounce = true
	    if PartB.Transparency == 0 then
           PartB.Tranparency = 1 
        elseif PartB.Transparency == 1 then
           PartB.Tranparency = 0     
        end
        wait(1)
	    Debounce = false
   end
end)

This should work I think.

It’s just that the part is still has collision even when transparent, so I changed the script so that it does not have collision for when it’s transparent.

This will work. Add the part you want to show up when you click into ReplicatedStorage, and do:

local replicatedStorage = game:GetService("ReplicatedStorage")
local partThatWillAppear = replicatedStorage.Part

local brick = script.Parent -- add a script into the block

brick.ClickDetector.MouseClick:Connect(function()
local clone = partThatWillAppear:Clone()
clone.Parent = workspace
clone.Position = Vector3.new() -- add the values
end)

You’re not clarifying anything about the other block. Where would it appear? What is the purpose of it? Is it an existing block?

1 Like