--If this is clicked function onClicked() --Checks if at the right timing if Value then --Make part function game . Workspace : makepart() -- I put "game . Workspace" to prevent another error. Although I think it's going to break the script. end end --Connect the function. script.Parent.ClickDetector.MouseClick:connect(onClicked) --Just a variable... Value = true -- ~Illuminati.~ The variable will change. -- If true that means the timing of --the person who clicked is correct. while true do Value = false wait(0) Value = true wait(1) end --Make the part function. local function makepart() --I'm wondering if these brackets are necessary. --The problem is that there's an error saying that I need to change this to local. local Make = Instance . new ("Part") Make . Parent = game . Workspace Make . Position = Vector3 . new (51, 30, 1) end
1) The function makepart
is not a member of workspace. You need to call it alone.
2) You need to wrap the while loop in a coroutine( or spawn or delay ), so that it lets the code under it run.
3a) Yes, you do need the "brackets"(they are not brackets, but parentheses), and don't localize the function, for then the onClicked function will not recognize the makepart function.
3b) Or, you could move the makepart function before the onClicked function and leave the while loop alone.
tl;dr answer:
local Value=true; local makePart;makePart=function() local Make=Instance.new('Part',workspace);--// You don't need to state another line to set the parent of Make. Make.Position = Vector3.new(51,30,1); end; function onClicked() if Value then makePart() end; end; script.Parent.ClickDetector.MouseClick:connect(onClicked) spawn(function()--// Starts the loop on another thread. while wait(1)do Value = false; wait(1)--// I had a feeling this was supposed to be 1. Value = true; end; end);
Side Note: Why are you doing game . Workspace,
, instead of game.Workspace?
So much pointless whitespace.
Why are you putting spaces?
Remove the spaces and test the code again.