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

Making a block invisible and non collidable for 20 seconds onclick not working?

Asked by 6 years ago
Edited 6 years ago

I have a brick that is supposed to (on click) disappear and lose collision for 20 seconds, this is the code, and position.

workspace > R123 > ClickDetector > Script

The script is as shown

function OnClick()
    if script.Parent.Parent.Transparency == 0 and script.Parent.Parent.CanCollide == true then
OnClick = script.Parent.Parent.Transparency == .6 and script.Parent.Parent.CanCollide == false

wait(20)

script.Parent.Parent.Transparency = 0 and script.Parent.Parent.CanCollide == true
end

end

script.Parent.MouseClick:Connect(OnClick)

nothing happens and the log shows

Enum.KeyCode.Unknown (x1)

even though I defined the key.

When I click on the brick, the console is claiming it is an unknown value as shown here --Enum.KeyCode.Unknown (x1)

[UPDATE]

the console randomly displays this in my mass of clicking

21:58:44.018 - Attempt to connect failed: Passed value is not a function 21:58:44.019 - Stack Begin 21:58:44.020 - Script 'Workspace.R123.ClickDetector.Script', Line 10 21:58:44.020 - Stack End

[UPDATE]

with InfernoExeuctioner's "conclusion" I get the error --

Enum.KeyCode.Unknown 22:00:57.444 - attempt to call a boolean value

[UPDATE]

Script has been edited to this, but I see no reason for it to not work other than what someone said about the "and" conditional.\

local part = script.Parent.Parent

function OnClick() if part.Transparency == 0 and part.CanCollide == true then part.Transparency = .6 part.CanCollide = false wait(20) part.Transparency = 0 part.CanCollide = true end end script.Parent.MouseClick:Connect(OnClick)

0
The site wouldn't let me place the script properly, but (end script.Parent.MouseButton1Click:connect(OnClick)) are in the script curtisman333 2 — 6y
0
Im sorry, I dont understand why the heck the code wont work curtisman333 2 — 6y
0
Wait,is the script in the click detector? KawaiiX_Jimin 54 — 6y
0
yea curtisman333 2 — 6y

4 answers

Log in to vote
0
Answered by
amanda 1059 Moderation Voter
6 years ago

ClickDetectors do not have an event called MouseButton1Click, however they do have one called MouseClick, which fires when someone left clicks the part containing the ClickDetector.

I am not sure were your output is relating to a KeyCode, elaborate on that and I will edit my answer.

Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

:connect() is deprecated, use :Connect()

local part = script.Parent.Parent ---you should make your part variable different from the function variable

--please keep in mind that you only use double equal signs when using conditional statements like if ..code.. then. 

function OnClick()
    if part.Transparency == 0 and part.CanCollide == true then
        part.Transparency = .6 
        part.CanCollide = false
        wait(20)
        part.Transparency = 0
        part.CanCollide = true
    end
end
script.Parent.MouseButton1Click:Connect(OnClick)

Will not work in this situation. MouseButton1Click should be used for GUIs.

script.Parent.MouseClick:Connect(OnClick)

MouseClick should be used for ClickDetectors

0
Thank you for your input but for whatever reason this script does not work with the (Enum.KeyCode.Unknown (x1)) still being displayed curtisman333 2 — 6y
Log in to vote
0
Answered by 6 years ago

You should listen to the other answers, but one big error I see is on line 3 and 7.

In line 3, you tried to set a variable named OnClick, but your function was already named OnClick, thus confusing the script.

In line 3, you also tried to assign a property using ==, when those are used exclusively in conditional statements.

Example:

if 2 + 2 == 4 then

while 2 + 2 == 4 do

repeat

until 2 + 2 ==4

The repeat loop would end instantly and the while loop wouldn’t break lol.

In line 7, you tried to set the property’s value, but added an and with no context. You use and in conditional statements as well.

0
I see what you mean, but even with that fixed, a new problem pops up, :: Enum.KeyCode.Unknown 22:21:30.450 - attempt to call a boolean value curtisman333 2 — 6y
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Just use this code:

local debounce = false
local part = game.Workspace.MyPart -- Change this to your actual part.
local clicker = part.ClickDetector -- Change this to your actual click detector.

function change()
    if not debounce then
        debounce = true -- You have to wait 20 seconds before the script lets you activate the function again.
        part.Transparency = 0.6
        part.CanCollide = false
        wait(20)
        part.Transparency = 0
        part.CanCollide = true
        debounce = false -- You can now click on the part and activate the function.
    end
end

clicker.MouseClick:Connect(change)

Let me know if this solves your problem!

EDIT

There is a keycode error apparently, however when I try this in my own game it works perfectly fine. No keycode error...

0
Nah, same keycode error curtisman333 2 — 6y
0
This is confusing... never mind Pixelated_MC 33 — 6y

Answer this question