How would i make this play every 5 seconds instead of looped?
–i’m new to scripting lol
local s = Instance.new("Sound")
s.Name = "Sound"
s.SoundId = "rbxassetid://3475602086"
s.Volume = 1
s.Looped = false
s.archivable = false
s.Parent = game.Workspace
wait(5)
s.Looped = true
s:play()
Wrap the s:play() in a while loop like this
while true do
s:play()
wait(5)
if (Condition) then
break
end
end
2 Likes
Hey there, SelectedArctic!
Looping using while or for loops isn’t a very good practice for this kind of stuff.
Instead we should use events.
I’ll put in a variable so at some point when it meets the condition it will stop itself, I’ll let you configure that, however.
Here is what we are after:
local stopPlaying = false
local s = Instance.new("Sound")
s.Name = "Sound"
s.SoundId = "rbxassetid://3475602086"
s.Volume = 1
s.Looped = false
s.archivable = false
s.Parent = game.Workspace
s.Stopped:connect(function()
if stopPlaying == false
s:Play()
end
end)
Hope this works for you!
Here is my reference for sound events, https://robloxapi.github.io/ref/class/Sound.html
(Reason for Github Link is being Roblox API pages are currently down)
3 Likes
Thanks to you both figured it out!
1 Like
wait so right now its playing out in the entire place so how would i make it play only from that part?
this is what i got lol
local script.Parent.Workspace.Head = s.Name = "sound"
local s = Instance.new("Sound")
s.Name = "Sound"
s.SoundId = "rbxassetid://3475603036"
s.Volume = 0.5
s.Looped = false
s.archivable = true
s.Parent = game.Workspace
while true do
s:play()
wait(7)
end
Parent the sound to a part to have it come from a specific location.
Also, mark on of the above posts as a solution so people know the answer to your question.
like this?
local script.Workspace.Parent.Head -- the part thats making the sound
i am new to scripting so. lol
yea, just set sound.Parent
to whatever it’s supposed to come from
so local script.sound.Parent.Head
that is not proper lua syntax. When using local
you are calling a variable. A variable must have a name, so doing script.sound.Parent.Head
won’t make a variable, and instead would call an error.