Question regarding functions

I have an inquiry regarding the functions. So, if I was thinking to make a sound along with a new colour, how would I make them both happen at the same time? For instance, this would be an example of a code:

local function SFX(id)
     local se = Instance.new("Sound")
     se.Parent = script.Parent
     se.SoundId = id
     se:Play()
     wait(10)
     se:Destroy()
end
SFX()
script.Parent.Color = Color3.fromRGB(255,255,255)
-- other random code that goes further, but I want them to go at the same time

Is there any way to move forward from SFX’s wait? Yes, there may be ways around this, but I’m asking as I’m curious.

Well you could color the part first, and then call the SFX function, but if you can’t do that then you can wrap it in a coroutine:

coroutine.wrap(SFX)()

You could use delay() to fix that

I see, thank you. I’ll use this for my future projects.

1 Like

If you want both the SFX() and the script.Parent.Color to be ran at the same time, you’re better off switching the two around so they both run.

script.Parent.Color = Color3.fromRGB(255,255,255)
SFX()