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!
You will first want to add a ClickDetector into the part. If this is a server script, you would also need to determine the "click state" of the part. This can be done using a BoolValue.
local clickdetector = Instance.new("ClickDetector", game.Workspace.ButtonPart) local clickstate = Instance.new("BoolValue", clickdetector) -- clickstate will be true for left click, back to false for right click clickdetector.MouseClick:Connect(function() if clickstate.Value == false then clickstate.Value = true -- Set click status to "left clicked" end while true do wait() if clickstate.Value == false then return end -- Check if right clicked local h = Instance.new("Part", game.Workspace) h.Position = Vector3.new(36, 0.5, 21.5) end end) clickdetector.RightMouseClick:Connect(function() if clickstate.Value == true then -- Check if left-clicked clickstate.Value = false -- Set to right clicked status end end)
game.Workspace.ButtonPart.Touched:Connect(function() while true do wait(0.1) local h = Instance.new("Part", game.Workspace) h.Position = Vector3.new(36, 0.5, 21.5) if game.Workspace.ButtonPart.Touched then break end end end)
i made it so both the times touch