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?
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!
You can make a block disappear using its Transparency property (1 is invisible, 0 is solid)
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)
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:
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
Closed as Not Constructive by User#5423
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?