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

Why is my table going through the properties one by one?

Asked by 2 years ago
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local shadow = ReplicatedStorage:WaitForChild("shadow")

local function shadowjump(player, mouse)
    local charstuff = player.Character:GetChildren()
    for i, v in pairs(charstuff) do
        if v:IsA("Part") then
            for count = 1,10 do
                v.Transparency = v.Transparency + .1
                wait(.1)
            end
        end
    end
    for i, v in pairs(charstuff) do
        if v:IsA("Part") then
            for count = 1,10 do
                v.Transparency = v.Transparency - .1
                wait(.1)
            end
        end
    end
end

shadow.OnServerEvent:Connect(shadowjump)

--  player.Character.HumanoidRootPart.CFrame = CFrame.new(mouse)

What I'm trying to do is change all the parts in the character at once to progressively turn invisible, but it goes from one part to the other in a row. Like first it does the right leg, then the right arm, then the torso, and so on and so forth. How would I go about making it all progressively turn transparent at once?

2 answers

Log in to vote
0
Answered by
Neatwyy 123
2 years ago

Here's your fixed code! It's sort of hard to explain, but if you analyze it you'll probably get it!

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local shadow = ReplicatedStorage:WaitForChild("shadow")

local function shadowjump(player, mouse)

    local charstuff = player.Character:GetChildren()

    for i = 1, 10 do
        for _, v in pairs(charstuff) do
            if v:IsA("BasePart") then
                v.Transparency += 0.1 -- // The same as v.Transparency = v.Transparency + 0.1
            end
        end
        wait(0.1)
    end

    for i = 1, 10 do
        for _, v in pairs(charstuff) do
            if v:IsA("BasePart") then
                v.Transparency -= 0.1
            end
        end
        wait(0.1)
    end

end

shadow.OnServerEvent:Connect(shadowjump)
Ad
Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

It only goes 1 by 1 because you have a 'wait()' at the end of the for loop and it makes it slower.

You should only delete the waits and it will look more nicer and it will not show the effect that it's going through properties one by one(although it is).

Answer this question