Why is this so slow?

Hello, I am making a disappearing staircase and I am using a modulescript for the settings. But for some reason it is very slow. It is supposed to be 1 second long but it is much longer.
My settings:

local stairSettings = {
	i2 = 100,
	transparencyChange = 1/100,
	waitTime = 3
}

return stairSettings

The stair item:

local ServerStorage = game:GetService("ServerStorage")
local stairSettings = require(ServerStorage.Settings)

local part = script.Parent

local i2 = stairSettings.i2
local TpC = stairSettings.transparencyChange
local waitTime = stairSettings.waitTime

part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		--Disappear Effect
		for i = 1, stairSettings.i2 do
			part.Transparency += TpC
			wait(i2/(i2 - 1))
		end
		
		--Collision and Reset
		part.CanCollide = false
		wait(waitTime)
		part.CanCollide = true
		part.Transparency = 0
	end
end)

Other than making a for i loop use TweenService, much smoother and better

I would but tweenservice is really confusing to me. And I don’t really understand it.

this would be a 1 second wait

and this would repeat 100 times. Meaning it would be a 100 second wait.

Still seems to be slow, and it isn’t 100 seconds long anyway.

As for a solution to this, you should simply do this:

for i = 1, stairSettings.i2 do
	part.Transparency += TpC
	task.wait(i2/i2/i2)
end

Also, I changed it to task.wait() since wait() is deprecated and isn’t good to use

local TweenService = game:GetService("TweenService")
local tweenInfo = (
	1, --time
)
local tween = TweenService:Create(part , tweenInfo , {Transparency = 1})
tween:Play()
tween.Completed:Wait()

if you divide something by itself, it will always lead to 1. Dividing i2 by 99 would lead to just above a one-second wait. Also, the for loop repeats 100 times since i2 is 100. Meaning, that this would be a 100-second wait, and that’s before adding the three seconds for it to reappear.

1 Like