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

Cframing door time not changing? [SOLVED]

I have a ModuleScript for the doors in my hangout place and when I change the time it takes for the door to move, It always stays at about 1.5 secs.

DoorScript (NOT the ModuleScript)

local module = require(game:GetService("ServerScriptService"):WaitForChild("DoorModule"))

wait()

for _, door in pairs(script.Parent:GetChildren()) do
	if door:IsA("BasePart") or door:IsA("UnionOperation") or door:IsA("Model") then
		module:New(door, door.Name)
	end
end

DoorModule

local doorStyles = { -- [Name of door] = {Studs to move, Time to move, Time open}
	["Door"] = {7, 0.5, 2.5},
	["BigDoor"] = {9, 1, 5}
}

local doorFrames = 100

local module = {}

function module:New(door, style)
	local style = doorStyles[style] or doorStyles[1]
	
	local debounce = false
	door.Touched:connect(function(part)
		if not debounce and part.Parent and game:GetService("Players"):GetPlayerFromCharacter(part.Parent) then
			debounce = true
			
			local originalCFrame = door.CFrame
			local endCFrame = originalCFrame + Vector3.new(0, style[1], 0)
			local loopStep = 1 / doorFrames
			local loopWait = style[2] / doorFrames
			
			for i = 0, 1 + loopStep, loopStep do
				door.CFrame = originalCFrame:lerp(endCFrame, i)
				wait(loopWait)
			end
			
			wait(style[3])
			
			for i = 0, 1 + loopStep, loopStep do
				door.CFrame = endCFrame:lerp(originalCFrame, i)
				wait(loopWait)
			end
			
			debounce = false
		end
	end)
end

return module

1 comment

0

Try looking at loopWait. I think I did it wrong.

1 answer

As of 11/8/16, It is float math. Frames max is lowest wait time * 100 [I think]

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