two people said I need to add another end on my other question, which I did but the end I added. was marked as red. can someone please help me out
local part = script.Parent
if game.PurpleKey.ClickDetector.MouseClick:Connect(function(plr) keyModule.Clicked = true wait(1) part:remove()
if game.PurpleKey.ClickDetector.MouseClick:Connect(function(plr) keyModule.Clicked = false wait(1) part:add()
end end
So whats happened is you haven't actually added in the ends to the functions.
01 | local part = script.Parent |
02 |
03 | if game.PurpleKey.ClickDetector.MouseClick:Connect( function (plr) and keyModule.Clicked = true then |
04 | wait( 1 ) |
05 | part:remove() |
06 | end ) |
07 |
08 | elseif game.PurpleKey.ClickDetector.MouseClick:Connect( function (plr) and keyModule.Clicked = false then |
09 | wait( 1 ) |
10 | part:add() |
11 | end ) |
12 |
13 | end |
When you close a function which looks like this (function()
, you put a bracket after the end
. You also can't put your function in an if
statement like that. I fixed up your script (I left comments for you to read).
01 | local part = script.Parent |
02 |
03 | game.PurpleKey.ClickDetector.MouseClick:Connect( function (plr) -- there's no player argument in a MouseClick event |
04 | if keyModule.Clicked = = false then -- using two different functions for the same event won't work because the game doesn't know which function you want to run. Instead, this if statement will work |
05 | keyModule.Clicked = true -- what is keyModule? (unless this is only a snippet of your code) |
06 | wait( 1 ) |
07 | part:Destroy() -- :Remove() is deprecated; use :Destroy() instead |
08 | else |
09 | keyModule.Clicked = false |
10 | wait( 1 ) |
11 | local part = Instance.new( "Part" , workspace) -- there is no such thing as :add() |
12 | end |
13 | end ) |