tech/game

21/07/31 Roblox Studio Tutorial: Doorway

tech-lover 2021. 7. 31. 18:27

Roblox Studio Tutorial: Secret Doorway (Touch)

: Open a doorway by touching a part near the door

 

https://youtu.be/2HT8DYED7MI

- lift up function

```

local part = script.Parent

local wall = game.Workspace.Wall

local canOpen = true

 

local function lift(otherPart)

    local partParent = otherPart.Parent

    local humanoid = partParent:FindFirstChildWhichIsA('Humanoid')

    if humanoid and canOpen then

        canOpen = false

        wall.Position = wall.Position + Vector3.new(0,12,0)

        wait(3)

        wall.Position = wall.Position + Vector3.new(0,-12,0)

        canOpen = true

    end

end

 

part.Touched:Connect(lift)

```

 

-- disapear

```

local part = script.Parent

local wall = game.Workspace.Wall.DoorWall

local canOpen = true

 

-- Make Wall Go Disapear

local function disapear(otherPart)

    local partParent = otherPart.Parent

    local humanoid = partParent:FindFirstChildWhichIsA('Humanoid')

    if humanoid and canOpen then

        canOpen = false

        wall.Transparency = 1

        wall.CanCollide = false

        wait(3)

        wall.Transparency = 0

        wall.CanCollide = true

        canOpen = true

    end

end

 

part.Touched:Connect(disapear)

```

 

Roblox Studio Tutorial: Pay to Open Door

https://youtu.be/UWCek_sOiZU

```

local part = script.Parent

local wall = game.Workspace.Wall.PayWall

local canOpen = true

 

local sound = part["Door Opening"--var for sound

local openDistance = 12 --height the door goes up

local steps = 10 --number of steps door take (more = smoother)

local stepSize = openDistance / steps --distance for each step

 

local function liftSmoothPayCheck(otherPart)

    local partParent = otherPart.Parent

    local humanoid = partParent:FindFirstChildWhichIsA('Humanoid')

    if humanoid and canOpen then

        

        -- Moeny check

        local player = game.Players:FindFirstChild(partParent.Name)

        if player and player.leaderstats.Money.Value >= 100 then

            

            player.leaderstats.Money.Value = player.leaderstats.Money.Value - 100

        

            canOpen = false

            sound:Play() --plays sound

            part.BrickColor = BrickColor.new('Lime green'--changes color

            --opens door

            for i = 1, steps do

                wall.Position = wall.Position + Vector3.new(0,stepSize,0)

                wait()

            end

            --wait time before close

            wait(2)

            --closes door

            for i = 1, steps do

                wall.Position = wall.Position - Vector3.new(0,stepSize,0)

                wait()

            end

            part.BrickColor = BrickColor.new('Really red'--changes color

            

            canOpen = true  

        end

        

    end

end



--part.Touched:Connect(lift)

--part.Touched:Connect(liftSmooth)

part.Touched:Connect(liftSmoothPayCheck)

--part.Touched:Connect(disapear)

```

 

Roblox Studio Tutorial: Open Door with Key

https://youtu.be/wp_CeZ0P9HQ

 

```

local part = script.Parent

local wall = game.Workspace.Wall.KeyWall

local canOpen = true

 

local function lift(otherPart)

    local partParent = otherPart.Parent

    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")

    if humanoid and canOpen then

        local player = game.Workspace:FindFirstChild(partParent.Name)

        if player then

            if player:FindFirstChild('Key'then

                canOpen = false

                wall.Transparency = 1

                wall.CanCollide = false

                local key = player:FindFirstChild('Key')

                key.Parent = game.Workspace

                key.Handle.Position = Vector3.new(math.random(-100,100),5,math.random(-60,-10))

                wait(2)

                wall.Transparency = 0

                wall.CanCollide = true

                canOpen = true

            end

        end

    end

end

 

part.Touched:Connect(lift)

```