I want to make a script that spawns in a block named Grass that is in Lighting. But if I click the button multiple times then multiple blocks will spawn, when I just want 1. Here is the script.
script.Parent.ClickDetector.MouseClick:connect(function() local grass = game.Lighting.Grass:Clone() grass.Parent = game.Workspace script.Parent.BrickColor = BrickColor.new("Really black") wait(1) script.Parent.BrickColor = BrickColor.new("Dark green") end)
There are a few methods of doing this, but I'll show you the simplest: Boolean logic
Basically, let the script set a variable to true after the grass has been cloned, and have the script only clone the grass if that variable is false. That way, the grass can only be cloned once. Like so:
local Bool = false script.Parent.ClickDetector.MouseClick:connect(function() if (not Bool) then --(not Bool) means the opposite of Bool. So if Bool is false, (not Bool) will return true and vice versa Bool = true --Sets the value of bool to true so that way (not Bool) will return false --Cloning code end end)
Hope this helped!