Boolean Value won't change from True to False when a script tries it

Hello!
So I have a little script here which is supposed to do stuff once you say a phrase

Issue is, I want the server script to change a boolean value, to set it from true to false, yet the script says that the values are “nil” and “could not find value”

I tried re writing the way of changing the value multiple times but it just doesn’t work for some reason

Flash = game.Lighting
debounce = false


function onChatted(msg, recipient, speaker) 
	source = string.lower(speaker.Name) 
	msg = string.lower(msg) 
	thecharacter = "I'm sorry"
	if (msg == string.lower(thecharacter)) and debounce == false then 
		game.Workspace.Struck:Play()
		Flash.Brightness = 100
		wait(.2)
		Flash.Brightness = 1
		wait()


		--telephone
		local telephone = game.Workspace.Telephone.ClickRegion
		telephone.Working.Value = false
		telephone.CallAvailable.Value = false
		telephone.Call:Stop()
		telephone.NumberNA:Stop()
		telephone.Ringing:Stop()
		telephone.Glitched:Stop() 
		
		debounce = true
	end 
end 
game.Players.ChildAdded:connect(function(plr)
	plr.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, plr) end) 
end)

Any error you guys could point out? Or is there something I’m missing entirely?
Thank you!

5 Likes

it is important to add a ‘local’ before variables to define them
to change them, you may not use ‘local’ if one is already defined

5 Likes

It still doesn’t work, but the script looks like this now

Flash = game.Lighting
debounce = false


function onChatted(msg, recipient, speaker) 
	local source = string.lower(speaker.Name) 
	msg = string.lower(msg) 
	local thecharacter = "I'm sorry"
	if (msg == string.lower(thecharacter)) and debounce == false then 
		game.Workspace.Struck:Play()
		Flash.Brightness = 100
		wait(.2)
		Flash.Brightness = 1
		wait()


		--telephone
		local telephone = game.Workspace.Telephone.ClickRegion
		telephone.Working.Value = false
		telephone.CallAvailable.Value = false
		telephone.Call:Stop()
		telephone.NumberNA:Stop()
		telephone.Ringing:Stop()
		telephone.Glitched:Stop() 
		
		debounce = true
	end 
end 
game.Players.ChildAdded:connect(function(plr)
	plr.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, plr) end) 
end)

Even putting it only as

game.Workspace.Telephone.ClickRegion.Working.Value = false

Still doesn’t work

2 Likes

Try using WaitForChild or FindFirstChild on the telephone and print the result. i.e workspace:FindFirstChild(“Telephone”)

1 Like

can you provide more clues
such as the explorer (where the telephone is located and their children)
and a screenshot of the error

1 Like

The way the debounce is implemented is inaccurate. Debounces are quick values that prevent functions from being run multiple times at the same time. But in the script, debounce is set to true and the if statement always evaluates to false. An example demonstrating how debounces work:

local RunService = game:GetService("RunService")
local debounce = false
local function saySomething()
    if not debounce then
        debounce = true
        task.wait(3)
        print("Hey!")
        debounce = false
    end
end

RunService.Heartbeat:Connect(saySomething)

The script above is supposed to print Hey! every 3 seconds (with an ms delay) with debounce. If you remove the debounce in the script, it will always say Hey!

This could be the only error.


As for an improvement to your script, you could rename your variables just as what you reference to. i.e., Lighting is a service, but it’s not acting like a flash because it has other properties or objects that could be placed beneath it that would reflect the same.

local Lighting = game:GetService("Lighting") --instead of flash

is this on a local or server script?