Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Kegani 31
6 years ago

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?

0
Use wait(time) T0XN 276 — 6y
0
add waits such as wait(.1) T1mes 230 — 6y

2 answers

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago

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) 
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 NathanAdhitya 124 — 6y
Ad
Log in to vote
2
Answered by
Dog2puppy 168
6 years ago
Edited 6 years ago

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

Answer this question