Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Getting more efficiency out of this script?

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)

2 comments

0

I'm pretty sure you can't Lerp models.

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.