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 3 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 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

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

local part = script.Parent

if game.PurpleKey.ClickDetector.MouseClick:Connect(function(plr) and keyModule.Clicked = true then
    wait(1) 
    part:remove()
end)

elseif game.PurpleKey.ClickDetector.MouseClick:Connect(function(plr) and keyModule.Clicked = false then
    wait(1) 
    part:add()
end)

end 
Ad
Log in to vote
0
Answered by 3 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).

local part = script.Parent

game.PurpleKey.ClickDetector.MouseClick:Connect(function(plr) -- there's no player argument in a MouseClick event
    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
        keyModule.Clicked = true -- what is keyModule? (unless this is only a snippet of your code)
        wait(1) 
        part:Destroy() -- :Remove() is deprecated; use :Destroy() instead
    else
        keyModule.Clicked = false
        wait(1)
        local part = Instance.new("Part", workspace) -- there is no such thing as :add()
    end
end)

Answer this question