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

Why does my door open super slowly?

Asked by 8 years ago

I am making a nice looking door that isn't an anchored brick that you can walk through. I am making a click door and the door's screen will quickly lower to allow a player to walk through.

Here's the script:

local gid = script.Parent.Configuration.GroupID
local ttw = script.Parent.Configuration.TimeToWait
local door = script.Parent.door
local l = script.Parent.Light
local d = false
local need = false
local ori

if gid.Value == 0 then
    need = false
else
    need = true
end

function open(p)
    if d == false then d = true else return end
    if need == true and p:IsInGroup(gid.Value) or need == false then
        l.BrickColor = BrickColor.new("Toothpaste")
        for i = door.CFrame.Y, door.CFrame.Y-door.Size.Y+0.2, -0.1 do
            door.CFrame = CFrame.new(Vector3.new(door.Position.X, i, door.Position.Z))
            wait(-1)
        end
        wait(ttw.Value)
        for i = door.CFrame.Y, door.CFrame.Y+door.Size.Y+0.2, 0.1 do
            door.CFrame = CFrame.new(Vector3.new(door.Position.X, i, door.Position.Z))
            wait(-1)
        end
        l.BrickColor = BrickColor.new("New Yeller")
    else
        Error()
    end
    d = false
end

function Error()
    l.BrickColor = BrickColor.new("Really red")
    wait(.5)
    l.BrickColor = BrickColor.new("New Yeller")
    wait(.5)
    l.BrickColor = BrickColor.new("Really red")
    wait(.5)
    l.BrickColor = BrickColor.new("New Yeller")
    wait(.5)
    l.BrickColor = BrickColor.new("New Yeller")
end

script.Parent.door.ClickDetector.MouseClick:connect(function(C)
    if C ~= nil then
        open(C)
    end
end)

I don't get anything in the output and the door lowers SLOWLY not quickly. I don't want people to hate my game just because the doors are incredibly slow.

Here is a graph of the door (with labels)

DOOR

I don't know how to fix this and I hope someone can help me.

1 answer

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

You move the door 0.1 studs after wait(-1).

You probably shouldn't be using -1. Any amount smaller than the default (which is usually about 0.034) will just be clamped to that. If you want to have as short of a pause as possible, then just use wait().

That's 0.1 / 0.03 studs/second, or 3.33 studs per second. That's about 20% of walking speed.

If you want it to move faster, use, e.g., -0.5 instead of -0.1 in your loops.

Using delta times

wait() isn't guaranteed to pause for any particular time. Especially when the game is busy, it could take much longer. This might mean your doors move not at all smoothly, and much slower than you expect.

wait() returns the actual amount of time that was waited. You can also use tick() to figure out how much time has elapsed.

In general, that looks like this:

local began = tick()
local start = thing.Position
local MAX = 20 -- studs. max height.
repeat
    wait()
    local elapsed = tick() - began -- seconds
    local SPEED = 16 -- studs/second
    local Y = math.min(elapsed * SPEED, MAX)
    thing.Position = start + Y
until Y >= MAX
0
Thx! It worked! creeper1164 17 — 8y
Ad

Answer this question