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

How can I get the increment to make sure the script is slow?

Hello, I'm trying to make a "cloak" button that makes you transparent when you click that button. It works, but the problem is it's supposed to be slow, and not fast. I thought putting "for i = 0,1,0.01" would make it slow, but it's like the speed of light.

local sd = game.Players.LocalPlayer.CharacterAdded:wait()

script.Parent.MouseButton1Click:connect(function(hi)
	for i = 0,1,0.01 do
		for i,v in pairs(sd:GetChildren()) do
			if v:IsA("Part") then
				v.Transparency = v.Transparency + i
			end
		end
	end
end)

GIF: https://gyazo.com/f2e4507926de4a1d437a121c5db0eefct

How can I make this script slow?

2 comments

0

Use wait(time)

0

add waits such as wait(.1)

2 answers

✓ Accepted answer

This is because you didn’t add a wait().

On line 4, you used a for loop with the variable i, but used another for loop inside that for loop with the same variable, i. It overrode your first i.

On a side note, switch to :Wait() and :Connect(), as ROBLOX have plans to remove the lowercase versions.

And what is that hi parameter at line 3? MouseButton1Click has no parameters.

local Players = game:GetService'Players'
local plr = Players.LocalPlayer or Players.PlayerAdded:Wait() -- Wait not wait
local char = plr.Character or plr.CharacterAdded:Wait() 

function fade(part, a, b, c)
    for transparency = a, b, c do
        part.Transparency = transparency
        wait(.01)
    end
end

script.Parent.MouseButton1Click:Connect(function() -- Connect not connect, no parameter
    for _, v in pairs(char:GetChildren()) do
        if v:IsA'BasePart' then
        fade(v, 0, 1, 0.1)
    end
    
end) 

1 comment

0

Nicely constructed. On the other hand, if you're doing this on the client, you can also use RenderStepped or Heartbeat for smoother experience

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