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

Admin door doesn't open?

Asked by 9 years ago
local Open = false
Admins = "alerttrains123","Player1"
function Click() 
    wait()
    if Click.Parent:findFirstChild("Humanoid") then 
        for i = 1,#Admins do
            if Click.Parent.Name == Admins[i] then
                if Open == false then
                    Open = true
                    script.Parent.Parent.DoorO1.Transparency = "0"
                    script.Parent.Parent.DoorO2.Transparency = "0"
                    script.Parent.Parent.DoorO1.CanCollide = true
                    script.Parent.Parent.DoorO2.CanCollide = true
                    script.Parent.Parent.DoorC1.Transparency = "1"
                    script.Parent.Parent.DoorC2.Transparency = "1"
                    script.Parent.Parent.DoorC1.CanCollide = false
                    script.Parent.Parent.DoorC2.CanCollide = false
                elseif Open == true then
                    Open = false
                    script.Parent.Parent.DoorO1.Transparency = "1"
                    script.Parent.Parent.DoorO2.Transparency = "1"
                    script.Parent.Parent.DoorO1.CanCollide = false
                    script.Parent.Parent.DoorO2.CanCollide = false
                    script.Parent.Parent.DoorC1.Transparency = "0"
                    script.Parent.Parent.DoorC2.Transparency = "0"
                    script.Parent.Parent.DoorC1.CanCollide = true
                    script.Parent.Parent.DoorC2.CanCollide = true
                    end
                end
            end
        end
    end

script.Parent.ClickDetector.MouseClick:connect(Click)

I took part of this script from somebody else and tried to implement it with mine, sadly the door will not open when I click it

0
You appear to be missing an argument in the Click function. What does the output print when you run the script? IcyArticunoX 355 — 9y
0
when I click the button it states: 17:32:38.762 - Stack Begin 17:32:38.765 - Script 'Workspace.Door.Click.Script', Line 5 17:32:38.767 - Stack End alerttrains123 10 — 9y
0
before the stack started it gave me: 17:32:38.760 - Workspace.Door.Click.Script:5: attempt to index global 'Click' (a function value) alerttrains123 10 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago

I think the problem is the Click is a function. When using a function like this, the parentheses should contain a word that represents the Player that clicked it. It can be named anything, but for the purposes of demonstration, let's name it "plr".

local Open = false
Admins = "alerttrains123","Player1"
function Click(plr) --plr is the Player who clicked 
    wait()
    if plr.Character:findFirstChild("Humanoid") then --use Character to access the Player's model
        for i = 1,#Admins do
            if plr.Character.Name == Admins[i] then
                if Open == false then
                    Open = true
                    script.Parent.Parent.DoorO1.Transparency = "0"
                    script.Parent.Parent.DoorO2.Transparency = "0"
                    script.Parent.Parent.DoorO1.CanCollide = true
                    script.Parent.Parent.DoorO2.CanCollide = true
                    script.Parent.Parent.DoorC1.Transparency = "1"
                    script.Parent.Parent.DoorC2.Transparency = "1"
                    script.Parent.Parent.DoorC1.CanCollide = false
                    script.Parent.Parent.DoorC2.CanCollide = false
                elseif Open == true then
                    Open = false
                    script.Parent.Parent.DoorO1.Transparency = "1"
                    script.Parent.Parent.DoorO2.Transparency = "1"
                    script.Parent.Parent.DoorO1.CanCollide = false
                    script.Parent.Parent.DoorO2.CanCollide = false
                    script.Parent.Parent.DoorC1.Transparency = "0"
                    script.Parent.Parent.DoorC2.Transparency = "0"
                    script.Parent.Parent.DoorC1.CanCollide = true
                    script.Parent.Parent.DoorC2.CanCollide = true
                    end
                end
            end
        end
    end

script.Parent.ClickDetector.MouseClick:connect(Click)

I hope this helps. If you found my answer helpful, you can upvote and accept it!

0
Aw, I got beat to the punch. IcyArticunoX 355 — 9y
0
I chose yours over Goulstem because it's easier to understand, thank you for getting it right yet keeping it simple for my mind to read and learn from! alerttrains123 10 — 9y
Ad
Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

You're attempting index your function name?

So yes, it's returning an error, because on line 5 and 7 you're saying 'Click.Parent', but 'Click' is a function value, not a variable.

So, i'm assuming you're attempting to check the player's name to open the door. For this you have to have a Parameter in your function that you're tying to your MouseClick event. Because the MouseClick event returns the player that clicked, then you can index the player through this parameter(:

Secondly, you're trying to define the 'Admins' through a singular variable.. if you do it like that then you will only get access to the first argument. Use a table, then iterate through it to check if they player that clicked is an 'Admin'.

And lastly, the Transparency value takes numbers for arguments, not strings. Take the numbers out of the quotations and then you're good(;


local Open = false Admins = {"alerttrains123","Player1"} --Made a table function Click(player) --'player' will be how you acces the player that clicked. wait() for i,v in pairs(Admins) do --Iterate through the 'Admin' table if v == player.Name then --Check if there's a match if Open == false then Open = true script.Parent.Parent.DoorO1.Transparency = 0 script.Parent.Parent.DoorO2.Transparency = 0 script.Parent.Parent.DoorO1.CanCollide = true script.Parent.Parent.DoorO2.CanCollide = true script.Parent.Parent.DoorC1.Transparency = 1 script.Parent.Parent.DoorC2.Transparency = 1 script.Parent.Parent.DoorC1.CanCollide = false script.Parent.Parent.DoorC2.CanCollide = false elseif Open == true then Open = false script.Parent.Parent.DoorO1.Transparency = 1 script.Parent.Parent.DoorO2.Transparency = 1 script.Parent.Parent.DoorO1.CanCollide = false script.Parent.Parent.DoorO2.CanCollide = false script.Parent.Parent.DoorC1.Transparency = 0 script.Parent.Parent.DoorC2.Transparency = 0 script.Parent.Parent.DoorC1.CanCollide = true script.Parent.Parent.DoorC2.CanCollide = true end end end end script.Parent.ClickDetector.MouseClick:connect(Click)
0
don't take offence to not accepting your answer, I can understand IcyArticunox a little better though because it's more basic, using the parameters got really confusing looking at yours which, if I need a similar script in the future, I might get confused with yours alerttrains123 10 — 9y
0
I'm just trying to get you used to proper termonology with Lua, sorry if I confused you. No hard feeling(: Goulstem 8144 — 9y

Answer this question