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

Can anyone help with this locking script?

Asked by 8 years ago

Also anyway to clean it up

glockdown = script.Parent.Parent.Parent.GlobalLockdown
dlockdown = script.Parent.Parent.Parent.DoorLockdown

script.Parent.ClickDetector.MouseClick:connect(function (pwc)
    print ("Check Click One")
        if dlockdown.Value == false and
        pwc.Name == workspace.ShipCrew.Captain.Value or 
        pwc.Name == workspace.ShipCrew.FirstOfficer.Value or 
        pwc.Name == workspace.ShipCrew.SecondOfficer.Value or 
        pwc.Name == workspace.ShipCrew.EngineeringChief.Value or 
        pwc.Name == workspace.ShipCrew.EngineeringJuniorOne.Value or 
        pwc.Name == workspace.ShipCrew.EngineeringJuniorTwo.Value or 
        pwc.Name == workspace.ShipCrew.TacticalChief.Value or 
        pwc.Name == workspace.ShipCrew.TacticalJuniorOne.Value or
        pwc.Name == workspace.ShipCrew.TacticalJuniorTwo.Value or
        pwc.Name == workspace.ShipCrew.MedicalChief.Value or
        pwc.Name == workspace.ShipCrew.MedicalJuniorOne.Value or
        pwc.Name == workspace.ShipCrew.MedicalJuniorTwo.Value or 
        pwc.Name == workspace.ShipCrew.ScienceChief.Value or
        pwc.Name == workspace.ShipCrew.ScienceJuniorOne.Value or
        pwc.Name == workspace.ShipCrew.ScienceJuniorTwo.Value or
        pwc.Name == workspace.ShipCrew.OperationsChief.Value or
        pwc.Name == workspace.ShipCrew.OperationsJuniorOne.Value or
        pwc.Name == workspace.ShipCrew.OperationsJuniorTwo.Value 
        then 
        print("Check One")
         dlockdown.Value = true
         script.Parent.Lock:Play()
end
end)

    script.Parent.ClickDetector.MouseClick:connect(function (pwc)
    print ("Check Click Two")
        if dlockdown.Value == true and
        pwc.Name == workspace.ShipCrew.Captain.Value or 
        pwc.Name == workspace.ShipCrew.FirstOfficer.Value or 
        pwc.Name == workspace.ShipCrew.SecondOfficer.Value or 
        pwc.Name == workspace.ShipCrew.EngineeringChief.Value or 
        pwc.Name == workspace.ShipCrew.EngineeringJuniorOne.Value or 
        pwc.Name == workspace.ShipCrew.EngineeringJuniorTwo.Value or 
        pwc.Name == workspace.ShipCrew.TacticalChief.Value or 
        pwc.Name == workspace.ShipCrew.TacticalJuniorOne.Value or
        pwc.Name == workspace.ShipCrew.TacticalJuniorTwo.Value or
        pwc.Name == workspace.ShipCrew.MedicalChief.Value or
        pwc.Name == workspace.ShipCrew.MedicalJuniorOne.Value or
        pwc.Name == workspace.ShipCrew.MedicalJuniorTwo.Value or 
        pwc.Name == workspace.ShipCrew.ScienceChief.Value or
        pwc.Name == workspace.ShipCrew.ScienceJuniorOne.Value or
        pwc.Name == workspace.ShipCrew.ScienceJuniorTwo.Value or
        pwc.Name == workspace.ShipCrew.OperationsChief.Value or
        pwc.Name == workspace.ShipCrew.OperationsJuniorOne.Value or
        pwc.Name == workspace.ShipCrew.OperationsJuniorTwo.Value  
         then 
    print("Check Two")
         dlockdown.Value = false
         glockdown.Value = false
         script.Parent.Unlock:Play()
     end
end)


0
It locks, but wont unlock BearKranz 41 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

Since we've already discussed the problems on Skype, here's the fixed script:

glockdown = script.Parent.Parent.Parent.GlobalLockdown
dlockdown = script.Parent.Parent.Parent.DoorLockdown

--List the ranks that can use the door here, follow the format shown.
local ranks = {
"Captain",
"FirstOfficer",
"SecondOfficer",
"EngineeringChief",
"EngineeringJuniorOne",
"EngineeringJuniorTwo",
"TacticalChief",
"TacticalJuniorOne",
"TacticalJuniorTwo",
"MedicalChief",
"MedicalJuniorOne",
"MedicalJuniorTwo",
"ScienceChief"
"ScienceJuniorOne",
"ScienceJuniorTwo",
"OperationsChief",
"OperationsJuniorOne",
"OperationsJuniorTwo"
}
--End rank list

script.Parent.ClickDetector.MouseClick:connect(function (pwc)
    print (pwc.Name.." clicked")
    if dlockdown.Value == false then
        print("Door is not locked.")
        for i,v in ipairs(ranks) do
            if pwc.Name == workspace.ShipCrew[v].Value then
                print(v.Value.." "..pwc.Name.." passed check. Locking door.")
                dlockdown.Value = true
                script.Parent.Lock:Play()
            else
                print(pwc.Name.." did not pass check.")
            end
        end
    elseif dlockdown.Value == true then
        print("Door is locked.")
        for i,v in ipairs(ranks) do
            if pwc.Name == workspace.ShipCrew[v].Value then
                print(v.Value.." "..pwc.Name.." passed check. Unlocking door.")
                dlockdown.Value = false
                script.Parent.Lock:Play()
            end
        end
    end
end)

The reason it was throwing the "Unknown Global" was because I forgot to make the ranks strings, so ROBLOX was looking for the variables "Captain", "FirstOfficer", etc. That's fixed now.

Ad

Answer this question