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

How the global variables works?

Asked by
zeptak 4
5 years ago

I wanted to make doors with _G but I don't even know how it works.

local a = workspace.VisitorEntrance.Door:GetChildren()

for i=1,#a do
    wait()
    if a[i].ClassName == 'Part' or a[i].ClassName == "UnionOperation" then
    local b = Instance.new("NumberValue")
    b.Parent = a[i]
    b.Name = "Transp"
    b.Value = a[i].Transparency
    end
end

function _G.VisitorOpen()
    for i=1,#a do
        a[i].Transparency = 1
        a[i].CanCollide = false
    end
end


script.Parent.ClickDetector.MouseClick:Connect(_G.VisitorOpen)

The script normally works but when I make another script where is to run _G.VisitorOpen() Then it prints "Attempt to call a nil value".

0
is it possiblr to not make the doors with _G if it is uneccessary yet hard? TheluaBanana 946 — 5y

Answer this question