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

Using BoolValue to share a debounce for two scripts won't work, why?

-- Context Of Problem -- My script is being used to make a timed challenge, climbing a "Megatower." The Megatower has two entrances, and after ten seconds starting when the player touches either pad or pad2 the player is teleported to the block "landZone." I created a BoolValue called "debounce" to work for both pads, each having there own scripts, which are identical. However, when I touch either pad, the BoolValue will not change. So I can activate the other pad after activating the first, running two instances of the script, creating odd errors.

-- Question -- How can I have the script turn the BoolValue "debounce" false? script.Parent.Parent.debounce.Value = false won't work. Any ideas on what is wrong, or a fix?

Thanks.

local self = script.Parent
local pad = script.Parent.Parent.Pad
local pad2 = script.Parent.Parent.Pad2
local gate = script.Parent.Parent.InvisEntry
local gate2 = script.Parent.Parent.InvisEntry2
local debounce = script.Parent.Parent.debounce.Value
local speaker = script.Parent.Parent["Megatower Is Ready"]
modelname="landZone"

function onTouch(Brick)
	if debounce == false then
	local player = Brick.Parent:findFirstChild("Humanoid")
	if player ~= nil then
		debounce = true
		speaker.Name = "Climb On!"	
		gate.CanCollide = false
		gate2.CanCollide = false
		pad.BrickColor = BrickColor.new("Bright yellow")
		pad2.BrickColor = BrickColor.new("Bright yellow")
		wait(10)
		local teleportto=script.Parent.Parent:findFirstChild(modelname)
				if teleportto~=nil then
					local torso = player.Parent.Torso
					local location = teleportto.Position

					local x = location.x
					local y = location.y
					local z = location.z
				
					x = x
					z = z 
					y = y 

					local cf = torso.CFrame
					local lx = 0
					local ly = y
					local lz = 0
					torso.CFrame = CFrame.new(Vector3.new(x,y,z), Vector3.new(lx,ly,lz))
				end
		speaker.Name = "Megatower Must Reset"						
		gate.CanCollide = true
		gate2.CanCollide = true
		pad.BrickColor = BrickColor.new("Bright red")
		pad2.BrickColor = BrickColor.new("Bright red")
		wait(20)
		speaker.Name = "Megatower Is Ready"
		pad.BrickColor = BrickColor.new("Bright green")
		pad2.BrickColor = BrickColor.new("Bright green")
		debounce = false
			end
		end 
	end

self.Touched:connect(onTouch)

1 answer

✓ Accepted answer

The problem here is your line 06:

local debounce = script.Parent.Parent.debounce.Value

Is basically saying local debounce = false, because by adding .Value in your variable you are grabbing the bool in its current state, which happens to be false.

Your variable should be:

local debounce = script.Parent.Parent.debounce

And to switch from true and false more efficently say:

local debounce = script.Parent.Parent.debounce

debounce = not debounce
-- Code
debounce =  not debounce

Sorry for giving you a long answer to a simple question. Scripter Helper stabbed me 200001023123 times for giving too short of answers.

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