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

I want to make a door using servo type hinge but its wrong, can someone help me?

Asked by 7 years ago
local hinge = script.Parent.Frame.Hinge
local door = script.Parent.Door
local handle1 = script.Parent.Handle1
local handle2 = script.Parent.Handle2
local targetAngle = -90
local open = false

local function DoorFunction ()
    if open == false then
        hinge.TargetAngle = 0
        open = true
        print("open")
    end
    if open == true then
        hinge.TargetAngle = targetAngle
        open = false
        print("close")
    end
end

handle1.ClickDetector.MouseClick:connect(DoorFunction)
handle2.ClickDetector.MouseClick:connect(DoorFunction)

i want to make the door opens when the handle is clicked and closes when the handle is clicked again

PLS help!

1 answer

Log in to vote
0
Answered by 7 years ago

I just connected the 2 'if's, if open is false then it read the statement(Updates 'open' to true) and reads another condition which checks if open is true... gotta stop here, bai

http://wiki.roblox.com/index.php?title=Conditional_statement#Elseif

local hinge = script.Parent.Frame.Hinge
local door = script.Parent.Door
local handle1 = script.Parent.Handle1
local handle2 = script.Parent.Handle2
local targetAngle = -90
local open = false

local function DoorFunction ()
    if open == false then
        hinge.TargetAngle = 0
        open = true
        print("open")

    elseif open == true then
        hinge.TargetAngle = targetAngle
        open = false
        print("close")
    end
end
end

handle1.ClickDetector.MouseClick:connect(DoorFunction)
handle2.ClickDetector.MouseClick:connect(DoorFunction)
0
:( User#17685 0 — 7y
0
Thx for the help! Now i can make a lot of things using this. : ) FriendlyKevinPotato -8 — 7y
Ad

Answer this question