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

Can anyone help me with my CFrame door(s) script?

Asked by
Xetrax 85
9 years ago

I have yet another CFraming problem... and yet again it has to do with doors...

--[Constants]:
local Entry = script.Parent
local D1 = Entry.L_Door
local D2 = Entry.R_Door
local CD1 = Entry.B1.ClickDetector
local CD2 = Entry.B2.ClickDetector
local Move = Entry.Motion
local Lock = Entry.Close

--[Bool Values]:
local Open = false

--[String Values]:
local TextCode = "ABCD"

--[Number Values]:
local NumCode = 1234

--[External Values]:
local Values = Entry.DoorValues
local DoorStatus = DoorValues.Status
local DoorFault = DoorValues.Fault
local InMotion = DoorValues.Moving
local CodeType = DoorValues.C_Type  --[0 = No Code, 1 = Keypad, 2 = Number, 3 = Group, 4 = Specific Person/People]

--[Code]:

function MoveDoors(User)
    --PromptCode(User)
    if Open == false and (DoorStatus.Value ~= 4) then
        DoorStatus.Value = 4
        OpenDoors()
        DoorStatus.Value = 2
    elseif Open == true and (DoorStatus.Value ~= 3) then
        DoorStatus.Value = 3
        CloseDoors()
        DoorStatus.Value = 1
    end
end

function PromptCode(User)
    if CodeType.Value ~= 0 then
        --Incomplete function, I got this...
    elseif CodeType.Value == 0 then
        --FutureCodeToCome
    end
end

function OpenDoors()
    if InMotion.Value == true then return end
        InMotion.Value = true
        Lock:Stop()
        Move:Play()
        for M = 1, 60 do
            D1.CFrame = D1.CFrame * CFrame.new(-0.2,0,0)
            D2.CFrame = D2.CFrame * CFrame.new(0.2,0,0)
            Wait(0.05)
        end
        Move:Stop()
        InMotion.Value = false
        Lock:Play()
        Open = true
        Wait(1.5)
end

function CloseDoors()
    if InMotion.Value == true then return end
    InMotion.Value = true
    Lock:Stop()
    Move:Play()
    for M = 1, 60 do
        D1.CFrame = D1.CFrame * CFrame.new(0.2,0,0)
        D2.CFrame = D2.CFrame * CFrame.new(-0.2,0,0)
        Wait(0.05)
    end
    Move:Stop()
    InMotion.Value = false
    Lock:Play()
    Open = false
    Wait(1.5)
end

CD1.MouseClick:connect(function(P) MoveDoors(P) end)
CD2.MouseClick:connect(function(P) MoveDoors(P) end)

As you may be able to tell, this is one of my newer codes... so it's more structured...

0
What is the actual problem? 2eggnog 981 — 9y
0
The door's work in offline mode, but they do not work in online mode, and I have no idea why... Xetrax 85 — 9y
0
I am not sure if it has to do with the fact that "DoorValues" is a configuration object... Because I have a computer/database that stopped functioning too and it stores variables via a config. obj. Xetrax 85 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

Some of your values are incorrect. The whole "External Values" section is wrong because you connect them to nil values. You have to connect it to the game, or to another Variable, and in this case you have done neither. It would have to look something like this:


--[External Values]: local Values = game.Workspace.Entry.DoorValues local DoorStatus = game.Workspace.Entry.DoorValues.Status local DoorFault = game.Workspace.Entry.DoorValues.Fault local InMotion = game.Workspace.Entry.DoorValues.Moving --I'm not sure if "Moving" is a value. I assume it's a debounce, so I'll leave it be. local CodeType = game.Workspace.Entry.DoorValues.C_Type --[0 = No Code, 1 = Keypad, 2 = Number, 3 = Group, 4 = Specific Person/People

Fix your other values as well, make sure to properly write the hierarchy.

Also, are "Lock" and "Move" audio bits? If not, then :Stop and :Play are useless.

Lastly, your connection line is.. Strange, to say the least. I'm not sure if that is actually a functioning bit of code, as I've never seen something like that, but your connection line should look something like this:

CD1.MouseButton1Down:connect(MoveDoors) --I'm not sure if MouseButton1Down works on parts, if not then my apologies, as I mostly work with Guis.
CD2.MouseButton1Down:connect(MoveDoors)

Try that, and then let me know what your Output says and what specifically the problem is.

0
Actually, the mousebutton1down refers to the clickdetector, if you followed the local preset values, the click detectors are named "CD" Xetrax 85 — 9y
0
Open is the DB, lock and move are audio, and the moving variable just tels when the door is actually moving (i.e. either closing, or opening) Xetrax 85 — 9y
0
It might be the mousebutton1down though, but It is working with a ClickDetector, not a TextButton. Xetrax 85 — 9y
0
I know that the Click Detectors were named "CD," that's not why I called your connection lines strange. I don't want you to change it to a TextButton either, I was just skeptical as to whether or not MouseButton1Down works on Parts. SlickPwner 534 — 9y
0
Yes, but the mouseclick has worked in most of my other models, the line of code just returns the player who clicked, so they specifically can be sent a GUI with the code (when I finish that func.). Xetrax 85 — 9y
Ad

Answer this question