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