Meshes of a model change transparency individually

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
			model.Transparency = 0
			model.Transparency = 1
			model.Transparency = 0

Each wait statement halts the code and then resumes it. I suggest using task.spawn.

1 Like

I’m stil learning scripting and never heard ot task.spawn, do you mind explaining to me what it exactly does and how I should use it in my script?

I suggest learning the basics of coding in the DevHub. They can get quite handy!
Related tutorial for this kind of problem: Loops

And to make the loop not yield, use task.spawn()

task.spawn(function() -- makes the code not yield (or stop from the code to wait)
   -- code here
1 Like

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.")

-- Spawn a new thread to run the time-consuming task

-- Continue with other tasks on the main thread
print("Main thread continues running...")
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.