tech/game

21/07/19 How To Make in Roblox Studio (Door, Bed)

tech-lover 2021. 7. 19. 19:07

How to make an opening door in Roblox Studio

https://youtu.be/4wZK7dY66j0

Link to the script: https://github.com/denkodin/RobloxStu...

Link to the model in Roblox: https://www.roblox.com/library/480344...

 

- DoorScript

```

local Hinge = script.Parent.PrimaryPart

local opened = false

 

function OpenDoor()

    if opened == false then

        opened = true

        for i = 121 do

            script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0math.rad(5), 0))

            wait()

        end

    else

        opened = false

        for i = 121 do

            script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0math.rad(-5), 0))

            wait()

        end

    end

end

 

script.Parent.Handle1.ClickDetector.MouseClick:Connect(OpenDoor)

script.Parent.Handle2.ClickDetector.MouseClick:Connect(OpenDoor)

```

 

How to make a working bed in Roblox Studio

https://youtu.be/XgtVqWqDlQg

Link to the script: https://github.com/denkodin/RobloxStu...

Link to the model in Roblox: https://www.roblox.com/library/449199...

 

- BedScript.lua

```

local Cooldown = 3

local CurrentPlayer = nil

local CallbackHandler = nil

local CName = 'BedCooldown'

 

function StandupFromBed()

    if CurrentPlayer ~= nil and script.Parent:FindFirstChild("WeldConstraint"then

        local C = Instance.new("StringValue", CurrentPlayer)

        C.Name = CName

        game.Debris:AddItem(C, Cooldown)

        script.Parent.WeldConstraint:Remove()

        if CallbackHandler ~= nil then

            CallbackHandler:disconnect()

            CallbackHandler = nil

        end

        CurrentPlayer.Humanoid.PlatformStand = false

        CurrentPlayer.HumanoidRootPart.CFrame = script.Parent.CFrame * CFrame.Angles(0math.rad(180), 0) + Vector3.new(050)

        CurrentPlayer.HumanoidRootPart.Anchored = true

        wait()

        CurrentPlayer.HumanoidRootPart.Anchored = false

        CurrentPlayer = nil

    end

end

 

function LayToBed(character)

    if character ~= nil and not script.Parent:FindFirstChild("WeldConstraint"then

        CurrentPlayer = character

        CurrentPlayer.HumanoidRootPart.CFrame = script.Parent.CFrame * CFrame.Angles(math.rad(90), 0math.rad(-90))

        CurrentPlayer.Humanoid.PlatformStand = true

        local Weld = Instance.new("WeldConstraint", script.Parent)

        Weld.Part0 = script.Parent

        Weld.Part1 = character.HumanoidRootPart

        CallbackHandler = CurrentPlayer.Humanoid.Changed:Connect(function(property)

            if CurrentPlayer ~= nil and property == 'Jump' then

                StandupFromBed()

            end

        end)

    end

end

 

script.Parent.Touched:Connect(function(hit)

    local Character = hit.Parent

    if Character:FindFirstChild("Humanoid") and CurrentPlayer == nil and not Character:FindFirstChild(CName) then

        LayToBed(Character)

    end

end)

```