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!
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