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

expected to close (at line 6) got end?

Asked by 4 years ago

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

0
Please put your code in code blocks next time. AntiWorldliness 868 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

So whats happened is you haven't actually added in the ends to the functions.

01local part = script.Parent
02 
03if game.PurpleKey.ClickDetector.MouseClick:Connect(function(plr) and keyModule.Clicked = true then
04    wait(1)
05    part:remove()
06end)
07 
08elseif game.PurpleKey.ClickDetector.MouseClick:Connect(function(plr) and keyModule.Clicked = false then
09    wait(1)
10    part:add()
11end)
12 
13end
Ad
Log in to vote
0
Answered by 4 years ago

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).

01local part = script.Parent
02 
03game.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
13end)

Answer this question