I wan’t to make an effect that makes a roblox rig to change transparency constantly for some time. Take for example super mario when he eats a mushroom and he disappears and appears constantly before transforming.
So I want to do that but I encountered an issue. I used a loop that gets the rig’s children and changes their transparency. But instead of changing the transparency of the meshes at the same time, the meshes change individually.
Did some research on the devforum and didn’t found any solution.
Here is the script :
for _,model in pairs (model:GetChildren()) do
if model.ClassName == "MeshPart" then
model.Transparency = 1
wait(0.03)
model.Transparency = 0
wait(0.03)
model.Transparency = 1
wait(0.03)
model.Transparency = 0
--Etc
Basically when you use task.spawn, it creates a new thread which runs code separately. Suppose you have a normal task and a time consuming task which delays code execution which isn’t very good in general. You would run the time consuming task in a separate thread using task.spawn and run the normal task on the main thread.
-- Define a function to simulate a time-consuming task
local function timeConsumingTask()
print("Starting time-consuming task...")
wait(5) -- Simulate a task that takes 5 seconds to complete
print("Time-consuming task completed.")
end
-- Spawn a new thread to run the time-consuming task
task.spawn(function()
timeConsumingTask()
end)
-- Continue with other tasks on the main thread
print("Main thread continues running...")