[FIXED] Problem with Disable/Enable Generation Script

*Note: I’m pretty new to scripting

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I’m creating a game where every quarter of a second, a new part is generated, with some random properties. This is merely a game to practice what I have learned in tutorials. I’ve got the generation script working fine, however, I’m currently trying to make a script where only me, the owner can disable/enable the generation of the parts via ClickDetector and a Script in a Part.

  2. What is the issue? Include screenshots / videos if possible!
    The issue is pretty simple: When I initially click on the large part, the generation stops. However, when I click the part to re-enable generation, nothing happens. I’m unable to find any errors.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried reviewing the code several times, however, I can’t find anything. I have looked on the Developer Hub, however, I couldn’t find any information to help me. I’ve also tried to write the script differently to no avail. (I’m also trying to figure out a way to delete all the new parts when generation stops, which are instances generated by another script, but I can’t think of any way to do that)

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Mode = false

if Mode == false then
	script.Parent.ClickDetector.MouseClick:Connect(function(player)
		if player.Name == "TransportLogistics" then	
			wait(0.5)
			game.Workspace.GenScript.Disabled = true
			game.Workspace.Sign.SurfaceGui.TextLabel.Text = "Click to Enable Generation (Owner Only)"
			script.Parent.BrickColor = BrickColor.new("Bright red")
			Mode = true
		end
	end)
end
	
if Mode == true then
	script.Parent.ClickDetector.MouseClick:Connect(function(player)
		if player.Name == "TransportLogistics" then
			wait(0.5)
			game.Workspace.GenScript.Disabled = false
			game.Workspace.Sign.SurfaceGui.TextLabel.Text = "Click to Disable Generation (Owner Only)"
			script.Parent.BrickColor = BrickColor.new("Forest green")
			Mode = false
		end
	end)
end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

You did

if Mode == false then
	script.Parent.ClickDetector.MouseClick:Connect(function(player)
		if player.Name == "TransportLogistics" then	
			wait(0.5)
			game.Workspace.GenScript.Disabled = true
			game.Workspace.Sign.SurfaceGui.TextLabel.Text = "Click to Enable Generation (Owner Only)"
			script.Parent.BrickColor = BrickColor.new("Bright red")
			Mode = true
		end
	end)
end

What you should have did:

script.Parent.ClickDetector.MouseClick:Connect(function(player)
               if Mode == false then
		if player.Name == "TransportLogistics" then	
			wait(0.5)
			game.Workspace.GenScript.Disabled = true
			game.Workspace.Sign.SurfaceGui.TextLabel.Text = "Click to Enable Generation (Owner Only)"
			script.Parent.BrickColor = BrickColor.new("Bright red")
			Mode = true
		end
elseif Mode == true then
	script.Parent.ClickDetector.MouseClick:Connect(function(player)
		if player.Name == "TransportLogistics" then
			wait(0.5)
			game.Workspace.GenScript.Disabled = false
			game.Workspace.Sign.SurfaceGui.TextLabel.Text = "Click to Disable Generation (Owner Only)"
			script.Parent.BrickColor = BrickColor.new("Forest green")
			Mode = false
		end
	end)
end)

Explanation:
If your doing something like this:

local mode = true
if mode == true then -- It will only run once since it is not repeatedly doing it.
print('hi')
end

The script is still not working.

How about trying to make it all in 1 clickdectector function, see if this works.
If theres any issues please reply below.

Mode = false

	script.Parent.ClickDetector.MouseClick:Connect(function(player)
		if player.Name == "TransportLogistics" then	
			if Mode == false then
                wait(0.5)
				game.Workspace.GenScript.Disabled = true
				game.Workspace.Sign.SurfaceGui.TextLabel.Text = "Click to Enable Generation (Owner Only)"
				script.Parent.BrickColor = BrickColor.new("Really red")
				Mode = true
				return
			end
			if Mode == true then
                wait(0.5)
				game.Workspace.GenScript.Disabled = false
				script.Parent.BrickColor = BrickColor.new("Bright green")
				game.Workspace.Sign.SurfaceGui.TextLabel.Text = "Click to Disable Generation (Owner Only)"
				Mode = false
				return
			end
		end
	end)
1 Like