I'm trying to make a part disappear when a player clicks it and reappear at a chosen time does i'm absolutely clueless could anyone help?
How do i make a block disappear when a player clicks it and reappear at a chosen time?
2 answers
Step 1: Make part that you want player to click on. Step 2: Insert script and ClickDetector into the part. Step 3: Open script and write the following:
local debounce = false
script.Parent.Anchored = true -- Anchores brick
script.Parent.ClickDetector.MouseClick:Connect(function()
if debounce == false then
debounce = true
script.Parent.Transparency = 1 -- Makes Block Invisible
script.Parent.CanCollide = false -- Lets Player Walk Through Block
wait(2) -- Changes how long the block is not visible
script.Parent.Transparency = 0 -- Makes block visible again
script.Parent.CanCollide = true -- Players can now touch brick
debounce = false
end
end)
That should be it! I tested it myself!
1 comment
This is not a request site.
You can make a block disappear using its Transparency property (1 is invisible, 0 is solid)
Option 1: UserInputService V1
In order to retrieve the mouse click only using code, it is considered best to use the UserInputService, so this should be done with a LocalScript.
The mouse being clicked can be retrieved using the UserInputType for the MouseButton1 (left) after which, you can call the mouse's Target to make sure the response is not nil (they are pointing at the sky)
Finally we check that the part is a BasePart (which are parts which have the Transparency property) and make it disappear
Using a debounce, this will prevent the player from removing multiple blocks within a certain time frame.
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local debounce = true
game:GetService("UserInputService").InputBegan:Connect(function(input, event)
if input.UserInputType == Enum.UserInputType.MouseButton1 and mouse ~= nil and mouse.Target ~= nil then
if mouse.Target:IsA("BasePart") then
if debounce == false then return end
debounce = false
local obj = mouse.Target
local original = obj.Transparency
obj.Transparency = 1
obj.CanCollide = false
wait(3)
obj.Transparency = original
obj.CanCollide = true
debounce = true
end
end
end)
Option 2: UserInputService V2
If you want to remove any part with a certain name, you can set this as your checking parameter instead of :IsA("BasePart")
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local debounce = true
game:GetService("UserInputService").InputBegan:Connect(function(input, event)
if input.UserInputType == Enum.UserInputType.MouseButton1 and mouse ~= nil and mouse.Target ~= nil then
if mouse.Target.Name == "SpecialPart" then
if debounce == false then return end
debounce = false
local obj = mouse.Target
local original = obj.Transparency
obj.Transparency = 1
obj.CanCollide = false
wait(3)
obj.Transparency = original
obj.CanCollide = true
debounce = true
end
end
end)
For Options 1 and 2, if you want the change to be see by all players, you will need to use a RemoteEvent as highlighted here:
Option 3: ClickDetectors
Finally, you can also remove parts every time a person clicks on them directly by placing a ClickDetector within them.
script.Parent:WaitForChild("ClickDetector").MouseClick:Connect(function(player)
local original = script.Parent.Transparency
script.Parent.Transparency = 1
script.Parent.CanCollide = false
wait(5)
script.Parent.Transparency = original
script.Parent.CanCollide = true
end)
In the above example, you can use a Server Script under a part that also contains a ClickDetector Each of the above examples use a wait(#) to detect how long the part should remain invisible
3 comments
I'm serious Serpentine, you've gotta slow yourself down:)
I can't top this answer jeez...
This is not a request site.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
This is not a request site for code. Please follow https://scriptinghelpers.org/help/how-post-good-questions-answers
Please include your code or show us that you have attempted to solve your own question.