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

How do i make a delay to my sound in these lines of code?

Asked by 5 years ago

I am making some sick bullet whizzes, and i could not figure out how to make a delay to the second sound, because you hear the bullet impact first before you hear the shot. here is the code right here :

local Meta = Instance.new("Sound")
    Meta.Name = "Crack"
    Meta.SoundId = "rbxassetid://196857754"
    Meta.Volume = 0.7
    Meta.Pitch = 1
    Meta.Looped = true
    Meta.Parent = bullet
    Meta:play()
    local Feta = Instance.new("Sound")
    Feta.Name = "Plound"
    Feta.SoundId = "rbxassetid://1055286841"
    Feta.Volume = 2.5
    Feta.Pitch = 1
    Feta.Looped = false
    Feta.Parent = bullet
    Feta:play()

Feta is the bullet impact which will play first, however meta plays the same time as Feta which is why it needs a delay, now if i put a wait at:

local Feta = Instance.new("Sound")
        wait(2)
    Feta.Name = "Plound"
    Feta.SoundId = "rbxassetid://1055286841"
    Feta.Volume = 2.5
    Feta.Pitch = 1
    Feta.Looped = false
    Feta.Parent = bullet
    Feta:play()

it works but the whole gun delays which means it loads every two seconds so what must i do to make Meta delay for 2 seconds then play sound?

0
When you want to play a sound, you should do :Play() instead of :play() since :play() deprecated saSlol2436 716 — 5y
0
ok Carforlife1 59 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

I think you mean you want the delay for the sound without delaying the script. If that's what you mean, you can use delay to delay the sound without delaying the script.

local Meta = Instance.new("Sound")
Meta.Name = "Crack"
Meta.SoundId = "rbxassetid://196857754"
Meta.Volume = 0.7
Meta.Pitch = 1
Meta.Looped = true
Meta.Parent = bullet
Meta:play()
delay(2, function() -- Delays the function for 2 seconds
    local Feta = Instance.new("Sound")
    Feta.Name = "Plound"
    Feta.SoundId = "rbxassetid://1055286841"
    Feta.Volume = 2.5
    Feta.Pitch = 1
    Feta.Looped = false
    Feta.Parent = bullet
    Feta:play()
end)
-- Putting more here won't delay 2 seconds.
1
Also one more thing, the Pitch property is deprecated and is now instead PlaybackSpeed fighter169mobile 123 — 5y
0
This works like a charm! thank you, i was close from finding it but i was not sure if it was 100% right but this worked thanks alot! Carforlife1 59 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Flip it around. Create Feta play it first. Wait. Then create the other and play. Like this.

    local Feta = Instance.new("Sound")
    Feta.Name = "Plound"
    Feta.SoundId = "rbxassetid://1055286841"
    Feta.Volume = 2.5
    Feta.Pitch = 1
    Feta.Looped = false
    Feta.Parent = bullet
    Feta:play()
wait(2)
local Meta = Instance.new("Sound")
    Meta.Name = "Crack"
    Meta.SoundId = "rbxassetid://196857754"
    Meta.Volume = 0.7
    Meta.Pitch = 1
    Meta.Looped = true
    Meta.Parent = bullet
    Meta:play()
0
i tryed this already, this is what i was saying made my gun delay 2 seconds Carforlife1 59 — 5y

Answer this question