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

How to make a sound and tween play simultaneously?

Asked by 4 years ago

Hi, I am making a spike system for my game that will pop up and go back down. While the spike is popping up, I would like to play a sound effect with it. I made the script to play the tween and sound but the sound is not synced with the playing tween. Here is my code so far:

local Part = script.Parent
local TweenService = game:GetService("TweenService")
local sound = Part.Sound

local StartPos = Part.Position
local Goal = {}
Goal.Position = Vector3.new(StartPos-Vector3.new(0, 80, 0),StartPos)

local tweenInfo = TweenInfo.new(
    1,
    Enum.EasingStyle.Linear,
    Enum.EasingDirection.InOut,
    -1,
    true,
    4
)

local tween = TweenService:Create(Part, tweenInfo, Goal)


tween:Play()

wait(5)
while true do
    sound:Play()
    wait(8)
end

Is it something to do with timing? Or is it something else? Please help me.

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You can play the sound when the spike is in a certain position, kinda like this maybe, hope this helps!

local spike = -- your spike thing
local sound = -- your sound

when true do
    if spike.Position >= Vector3.new() then --the position when it's popping up 
        sound:Play
    end
    wait()
end
0
That won't work, as it will check the position as soon as the script runs. Use ":GetPropertyChangedSignal(prop)" Dan_PanMan 227 — 4y
Ad

Answer this question