Script isnt working.. How to fix?

This is a loop audio script that makes a audio play every couple of minutes, Dosen’t seem to work tho, Anyone know why?

while true do
local sound = game.Workspace.ann
if sound == nil then
local sound = Instance.new(“Sound”, game.Workspace)
sound.SoundId = “rbxassetid://130894143”
sound.Name = “ann”
end
if not sound.IsLoaded then
sound.Loaded:wait()
end
sound.TimePosition = 2
sound:Play()
wait(5)
end

1 Like
local sound = game.Workspace.ann

if sound ~= nil then

local sound = Instance.new("Sound", game.Workspace)

sound.SoundId = "rbxassetid://130894143"

sound.Name = "Explosion"

sound.Playing = true

sound:Play()

sound.Looped = true

sound.Parent = game.Workspace

elseif not sound.IsLoaded then

sound.Loaded:Wait()

else

sound.TimePosition = 2

sound:Play()


wait(5)

end
3 Likes

Thank you alot! This will totally help!

1 Like

Wait it didnt work… Do you have disc so we can talk and i show you more? @GoldenYoshi05

1 Like

Yea my discord is GoldenYoshi05#1957

1 Like

Sent! I am Reis!#0001, You should see me in your pendings.

1 Like

If you want the sound to loop you can just use the Looped property. Otherwise, there’s no reason for you to keep creating new sound instances since you already have one. Additionally you can use sound.Ended:Wait() to know when the sound has finished playing.

2 Likes

cc @GoldenYoshi05

If you do come to a solution, make sure to post it back here on the forums so that others that come across this thread can benefit from the solution. Thanks!

1 Like

You should change the title of the thread that more clearly explains what your problem is/was so that people who have a similar issue can find this thread at a latter point; that is how sites like stack overflow have saved so many coders time and sanity.

1 Like

First off, I would make it so that it is

while wait(math.random(60, 180)) do

end

this makes it so it’s actually once every “few minutes”.
Second, I would make sure that the sound works in the “preview” property of the sound as the ID could not be moderated yet by roblox.

Lastly, I would use:

local sounds = game:GetService("ContentProvider"):PreloadAsync({"assetid1", "assetid2", "assetid3"})

This effectively makes sure that the Content is loaded into the game.

2 Likes

Sorry, I’ll try do better next time posting!

1 Like