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

I want my door to open inwards but it just flys up in the sky?

Asked by 6 years ago

I dont know what is wrong i though it would just open up as a 90 degree angle but it does not it just flys up in the air. Here is my script

function onTouch(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        for i=0,80, 1 do
                    game.Workspace.F5T6.Orientation = game.Workspace.F5T6.Orientation + Vector3.new(0, i, 0)
        wait(0.1)
        end
    end
end

script.Parent.Touched:connect(onTouch)

pls halp

0
The door just wants to be free, free as a bird. DinozCreates 1070 — 6y
0
XD FantasticFrontierGuy 33 — 6y
0
Make sure it's a local script. Gameplay28 139 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

use CFrame.Angles() instead of setting the Orientation of that part, as it'll try to move around objects in its way. :connect() is deprecated, use :Connect(); deprecation

basic example:

local part = game.Workspace.F5T6 -- variable
local open = false -- boolean

local function onTouch(hit) -- use local functions
    if hit.Parent:FindFirstChild("Humanoid") then
        if open == false then
            part.CFrame = part.CFrame * CFrame.Angles(0,math.rad(90),0)
            open = true
        else
            part.CFrame = part.CFrame * CFrame.Angles(0,-math.rad(90),0)
            open = false
        end
    end
end

script.Parent.Touched:Connect(onTouch)

from what i see here that you want the door to swing smoothly, instead of just opening instantly. for this you could use lerp, though you'd need to have a hinge for the door to attach too and group it together and set the PrimaryPart to the hinge.

local part = game.Workspace.Model -- model
local open = false
local debounce = true -- debounce

local function onTouch(hit)
    if hit.Parent:FindFirstChild("Humanoid") and debounce == true then
        if open == false then
            debounce = false
            local setTurning = part.PrimaryPart.CFrame * CFrame.Angles(0,math.rad(90),0) -- creates the angle to lerp to

            for i = 0,1,0.1 do
                local lerping = part.PrimaryPart.CFrame:Lerp(setTurning,i) -- set a variable of :Lerp() and sets the alpha number to the value

                part:SetPrimaryPartCFrame(lerping) -- sets the cframe of all the children BaseParts relative to the PrimaryPart CFrame
                wait() -- waits by default aprox 0.03 sec
            end
            open = true
            wait(1)
            debounce = true
        else -- else if the boolean "open" is true then
            debounce = false
            local setTurning = part.PrimaryPart.CFrame * CFrame.Angles(0,math.rad(-90),0)

            for i = 0,1,0.1 do
                local lerping = part.PrimaryPart.CFrame:Lerp(setTurning,i)

                part:SetPrimaryPartCFrame(lerping)
                wait()
            end
            open = false -- sets it to false
            wait(1)
            debounce = true
        end
    end
end

part.Main.Touched:Connect(onTouch)

math.rad() converts degrees into radians in the argument

Links

Ad

Answer this question