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?
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)
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