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.
01 | local sd = game.Players.LocalPlayer.CharacterAdded:wait() |
02 |
03 | script.Parent.MouseButton 1 Click:connect( function (hi) |
04 | for i = 0 , 1 , 0.01 do |
05 | for i,v in pairs (sd:GetChildren()) do |
06 | if v:IsA( "Part" ) then |
07 | v.Transparency = v.Transparency + i |
08 | end |
09 | end |
10 | end |
11 | end ) |
GIF: https://gyazo.com/f2e4507926de4a1d437a121c5db0eefct
How can I make this script slow?
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.
01 | local Players = game:GetService 'Players' |
02 | local plr = Players.LocalPlayer or Players.PlayerAdded:Wait() -- Wait not wait |
03 | local char = plr.Character or plr.CharacterAdded:Wait() |
04 |
05 | function fade(part, a, b, c) |
06 | for transparency = a, b, c do |
07 | part.Transparency = transparency |
08 | wait(. 01 ) |
09 | end |
10 | end |
11 |
12 | script.Parent.MouseButton 1 Click:Connect( function () -- Connect not connect, no parameter |
13 | for _, v in pairs (char:GetChildren()) do |
14 | if v:IsA 'BasePart' then |
15 | fade(v, 0 , 1 , 0.1 ) |
16 | end |
17 |
18 | end ) |
You can use the wait()
function inside the for loop so that it’s slower. For more about wait()
: http://robloxdev.com/articles/Built-in-Functions-and-Variables/Roblox