I now understand this but when I click it the Grass spawns, then I click a button with destroy and it goes away, with Grass still in Lighting. When I click the green button again the Grass won't appear. Can anyone help?
Bool = false script.Parent.ClickDetector.MouseClick:connect(function() if (not Bool)then 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") Bool = true end end)
Your problem is that you're not reactivating your bool switch
- or officially known as debounce
.
This will cause your script to never pass the condition on line 4
.
So to fix? Reactivate your debounce.
local Bool = false script.Parent.ClickDetector.MouseClick:connect(function() if (not Bool)then --You checked if it's false Bool = true --Then set it to true, so the event won't re-iterate. local grass = game.Lighting.Grass:Clone() grass.Parent = workspace script.Parent.BrickColor = BrickColor.new("Really black") wait(1) script.Parent.BrickColor = BrickColor.new("Dark green") Bool = false --Reacitvate it! end end)
More info on debounces here.
You have Bool
acting as a sort of debounce for this function.
You require that Bool
is false
(ie not Bool
is true
) in order for your script to run -- but once you've made on blade, you set Bool
to true
(and nothing sets it to false
later).
I'm guessing what you meant to do was to disable making new ones while it's changing from black to green -- and then enable it again.
enabled = true -- Use a better name than "Bool" script.Parent.ClickDetector.MouseClick:connect(function() if enabled then local grass = game.Lighting.Grass:Clone() grass.Parent = game.Workspace script.Parent.BrickColor = BrickColor.new("Really black") enabled = false wait(1) script.Parent.BrickColor = BrickColor.new("Dark green") enabled = true end end)
If you just want to know if there's already a part named "Grass"
in the workspace, there's no need for a debounce at all:
script.Parent.ClickDetector.MouseClick:connect(function() if not workspace:FindFirstChild("Grass") then 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 end)
Locked by Goulstem and TheeDeathCaster
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?