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

Getting more efficiency out of this script?

Asked by 8 years ago

I have a script, but it seems really blocky, and slow.

I was wondering if it would be possible to make it more efficient.

local PLT = script.Parent.Parent.Parent
local movements = 60
local speed = 0.1
local open = false
script.Parent.MouseClick:connect(function() 
    if open == false then   
        for i=1,movements do
            wait(0.001)
            PLT:SetPrimaryPartCFrame(PLT.PrimaryPart.CFrame + Vector3.new(0,speed,0));
        end
        open = true
    elseif open == true then
        for i=1,movements do
            wait(0.001)
            PLT:SetPrimaryPartCFrame(PLT.PrimaryPart.CFrame + Vector3.new(0,-speed,0));
        end
        open = false
    end
end)
0
I'm pretty sure you can't Lerp models. TheHospitalDev 1134 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

There are only some small improvements but I would not use "wait()" to determine time. Use tick() as it will be more accrete.

local PLT = script.Parent.Parent.Parent
local movements = 60
local speed = 0.1
local open = false

script.Parent.MouseClick:connect(function() 
    if open then  -- can only be true or do the other so lets change this around
        for i=1,movements do
            wait(0.001)
            PLT:SetPrimaryPartCFrame(PLT.PrimaryPart.CFrame + Vector3.new(0,-speed,0));
        end
        open = false
    else 
        for i=1,movements do
            wait(0.001) consistant 
            PLT:SetPrimaryPartCFrame(PLT.PrimaryPart.CFrame + Vector3.new(0,speed,0));
        end
        open = true
    end
end)

Hope this helps.

Ad

Answer this question