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

How to delay a function? Easy? not use wait()

Asked by
14dark14 167
3 years ago

so I made this door script that plays a sound when its moving and when its closed

I want to make it so when the door closes it makes a "Thud" sound, but I need to delay the thud sound by 1 second because it plays too early

function open()
            local finish = script.Parent.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(90),0)
            sound:Play()
            click:Destroy()
            thud:Play() -- how to make this play 1 second later?
                for i = 0,1,.01 do
                    local cfm = script.Parent.PrimaryPart.CFrame:lerp(finish,i)
                    script.Parent:SetPrimaryPartCFrame(cfm)
                wait()
            end
            wait(1)
            script:Destroy()
end

Make the thud sound play 1 second later without stopping the script. That is without adding a "Wait()" function.

0
Try using a Co routine JesseSong 3916 — 3y

1 answer

Log in to vote
0
Answered by
14dark14 167
3 years ago

Nevermind found the answer myself

delay(.8,function()
            thud:Play()
            end)
0
dang I was about to answer with that ;c greatneil80 2647 — 3y
0
u should just use coroutinebut ok HappyTimIsHim 652 — 3y
0
coroutines are only used if you're planning to implement another script within a script. Dovydas1118 1495 — 3y
Ad

Answer this question