Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make a block disappear when a player clicks it and reappear at a chosen time? [closed]

Asked by 5 years ago

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?

0
This is not a request site for code. Please follow https://scriptinghelpers.org/help/how-post-good-questions-answers User#5423 17 — 5y
0
Please include your code or show us that you have attempted to solve your own question. User#5423 17 — 5y

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?

2 answers

Log in to vote
0
Answered by 5 years ago

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!

0
This is not a request site. User#5423 17 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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

1
I'm serious Serpentine, you've gotta slow yourself down:) Ziffixture 6913 — 5y
1
I can't top this answer jeez... User#26817 0 — 5y
0
This is not a request site. User#5423 17 — 5y