Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

error 'attempt to index global 'popen' (a boolean value)'?

Asked by 6 years ago

i have been experimenting with debouncing but im stuck with this error (title)

the error is at line 26 or 'popen.Value.Changed:connect(function()' i have tried without the .Value but that doesn't fix it is it because the value is created in the script?

any help is appreciated if there is anything missing just comment, Thanks

The Script: (a part of it)

popen = false
paropen = false
sopen = false
mopen = false
setopen = false

popen.Value.Changed:connect(function()
    if popen == true then
        paropen = false 
        sopen = false
        mopen = false
        setopen = false
    end
end)

2 answers

Log in to vote
1
Answered by 6 years ago

Well, your problem is simple. You're trying to use the Changed event on a Boolean variable. The Changed event only works on Roblox objects(Ex: BasePart, IntValue, etc.).

If you would like to use the Changed with this still, you would have to make popen a BoolValue stored somewhere. Here's an example using your desired code:

local popen = Instance.new("BoolValue")
popen.Name = "popen"
popen.Parent = script
local paropen = false --Local just puts the variable on the local scope.
local sopen = false
local mopen = false
local setopen = false

popen.Changed:connect(function(newValue)
    if newValue== true then
        paropen = false 
        sopen = false
        mopen = false
        setopen = false
    end
end)

Ad
Log in to vote
0
Answered by 6 years ago

An alternative to antonio6643's answer is to use a function instead of an event. If this variable is only needed by this script, replace the popen.Changed line with function SetPOpen(newValue) (removing the ) on line 16) and call that function instead of changing popen directly. If you want to be able to change POpen from any script, this will still work, but you need to put all this code in a ModuleScript, add the function to the Module table (just add module. right before SetPOpen).

Answer this question