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

C-Frame and debounce not working, why?

Asked by 8 years ago

So when the door gets clicked by Door Controller, it's meant to be opened, but it doesn't function. There are no errors in Script Analysis.

ref=script.Parent.ref
ref.Changed:connect(function()
    if ref.Value==nil then return end
    if ref.Value.Parent==nil then ref.Value=nil return end
    script.Parent.door.sign.SurfaceGui.TextLabel.Text=ref.Value.Name
end)
local door_debounce=false
function setDoorState(state)
    if door_debounce then repeat wait(math.random(1,10)/10) until not door_debounce end door_debounce=true
    if script.Parent.doorstate.Value==state then return end
    script.Parent.doorstate.Value=state
    if state==true then --Open
    for i=1, 40 do wait()
        for _,p in pairs(script.Parent.door:children()) do
            p.CFrame=p.CFrame*CFrame.new(-.1,0,0)
        end
    end
    else --Close
        for i=1, 40 do wait()
            for _,p in pairs(script.Parent.door:children()) do
                p.CFrame=p.CFrame*CFrame.new(.1,0,0)
            end
        end wait(0.5)
    door_debounce=false
end
script.Parent.action_door.Changed:connect(function()
    setDoorState(script.Parent.action_door.Value)
end)

1 answer

Log in to vote
0
Answered by 8 years ago

Try this and tell me what is the output

ref=script.Parent.ref
ref.Changed:connect(function()
    if ref.Value==nil then return end
    if ref.Value.Parent==nil then ref.Value=nil return end
    script.Parent.door.sign.SurfaceGui.TextLabel.Text=ref.Value.Name
end)
local door_debounce=false
function setDoorState(state)
print"1"
    if door_debounce then repeat wait(math.random(1,10)/10) until not door_debounce end 
print"2"
door_debounce=true
    if script.Parent.doorstate.Value==state then return end
    script.Parent.doorstate.Value=state
    if state==true then --Open
    for i=1, 40 do wait()
        for _,p in pairs(script.Parent.door:children()) do
            p.CFrame=p.CFrame*CFrame.new(-.1,0,0)
        end
    end
    else --Close
        for i=1, 40 do wait()
            for _,p in pairs(script.Parent.door:children()) do
                p.CFrame=p.CFrame*CFrame.new(.1,0,0)
            end
        end wait(0.5)
    door_debounce=false
print"3"
end
script.Parent.action_door.Changed:connect(function()
    print"Change State"
    setDoorState(script.Parent.action_door.Value)
end)
Ad

Answer this question