I'm a beginner scripter on Lua and while I was experimenting, I was trying to make it so that a player could click on a specific brick and it would cause parts to be generated until the brick was clicked once more by the player, but I cannot seem to write code that would do that.
Here's what I have so far (I do apologize if the code seems rudimentary, I've only been scripting for a few weeks):
game.Workspace.ButtonPart.Touched:connect(function()
while true do
wait()
local h = Instance.new("Part", game.Workspace)
h.Position = Vector3.new(36, 0.5, 21.5)
if game.Workspace.ButtonPart.RightMouseClick then
break
end
end
end)
If anyone could help me with this it would be much appreciated!

2 comments
So, to my understanding, the clickstate.Value will determine whether the while loop runs or not, and the while loop only runs as long as clickstate.Value = true, but when the part is clicked with the right side of the mouse, it sets the BoolValue back to false, meaning the while loop will return end.
That is correct.