Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make a debounce for multiple scripts?

To be more specific, I have this quiz, that is so far made up of only one question. What you're supposed to do, is do what a ScreenGui tells you. In this case, I have 3 bricks, all of different colors. The Gui says to step on the green one. So when you step on the green, the gui's text says "Good!", and if I step on a different brick, it says "Wrong!". The problem here is that, if I step on the green one, and then I step on another brick, the "Good!" swtiches to "Wrong!" and this is because the other scripts still work, even though I activated the first one. What I want is that the brick's scripts don't work if I'm stepping on a different brick. Here are the scripts:

Green Brick:

local part = script.Parent
local db = false
local msg = game.Workspace.Board.SurfaceGui.TextBox
local b = game.Workspace.Board

function CheckColor(hit)
	local human = hit.Parent:FindFirstChild("Humanoid")
	if not db then
		if human then
			
			db = true
			
			msg.Text = ("Good job!")
			wait(2)
			msg.Text = ("You can pass!")
			wait(2)
            msg.Visible = false
			
			for i = 0,1, 0.1 do
				b.Transparency = i
				wait(0.1)
				
			end
			
			b.CanCollide = false
			wait(3)
			b.CanCollide = true
			b.Transparency = 0
			msg.Visible = true
			msg.Text = ("Step on the green brick.")
			
			db = false		 
		
		end
	end
end


part.Touched:connect(CheckColor)

Red and Yellow brick:

local part = script.Parent
local db = false


function CheckColor(hit)
	local human = hit.Parent:FindFirstChild("Humanoid")
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if not db then
		if human then
			
			db = true
			
			game.Workspace.Board.SurfaceGui.TextBox.Text = ("Wrong!")
			wait(2)
			player:LoadCharacter()
			game.Workspace.Board.SurfaceGui.TextBox.Text = ("Step on the green brick.")
			
			db = false		 
		
		end
	end
end


part.Touched:connect(CheckColor)

2 comments

1

Don't use three separate scripts. Use one script. Or make a BoolValue in workspace called "Debounce"

2 answers

What you could do is use a ModuleScript that will return one value or you could use a global variable. The easier of these two would be to just use a global variable and you would do this by in any server sided script declaring it.

_G.Number = 1
_G.Boolean = true
_G.String = 'string'

And these will be able to be referenced in any script just by using the prefix "_G.".

The next method is the one where you can declare your boolean value inside of a ModuleScript and then reference this by other scripts by using require. So create a ModuleScript and inside just type:

local Boolean = true
return Boolean

and then in all of your other scripts you can reference this by doing:

local Boolean = require(LocationOfModuleScript)
print(Boolean) --> true

1 comment

0

Never tell people to use a global variable. That's terrible advice. Global variables are terrible and you don't need to use them because there's always another way to do what you're attempting.

DevDgilly is right, but global variubles cause latency. Witch you don't want. Or you can use his ModuleScript method. Also, this is ridiculous, we use Tab to indent! SO that is why there is uneven code. Here is my awnswer.

local part = script.Parent
local db = false
local msg = game.Workspace.Board.SurfaceGui.TextBox
local b = game.Workspace.Board
local dbd =    --Insert the location of other script(s) here
function CheckColor(hit)

    local human = hit.Parent:FindFirstChild("Humanoid")
    if not db and if human then -- Shortening the script.

             db = true
		dbd.Disabled = true --basically temporarily turning off the other script(s)
            msg.Text = ("Good job!")
            wait(2)
            msg.Text = ("You can pass!")
            wait(2)
            msg.Visible = false

            for i = 0,1, 0.1 do
                b.Transparency = i
                wait(0.1)
            end

            b.CanCollide = false
            wait(3)
            b.CanCollide = true
            b.Transparency = 0
            msg.Visible = true
            msg.Text = ("Step on the green brick.")
		
		dbd.Disabled = false --Turning on the other script(s)
            db = false     

        end
    end
end

part.Touched:connect(CheckColor)

So what disabling does is, well, disable! So if you do print("Hello!") and disable it, it wont print "Hello!" Do the same with other script(s)

This discussion is preserved as it was. New answers, comments, and votes are closed.