How to play audio every x amount of minutes when wearing accessory

In the sound element.


(Paste the ID of the audio in SoundId)

1 Like

You assign in the Sound itself via the Explorer. Get the id you want to use, click on the Sound i nthe explorer, go into its property and click on SoundId, paste the ID and press enter

2 Likes

where in the branch of my accessory do i place the script? handle parent? mesh?
I have it on serverscriptservice

You can put anywhere in the script, I would recommend putting the script nad the sound as parents of the Accessory instance

Wouldn’t wait(200) sometimes be over 200 because of server lag?

1 Like

I’m not sure, but I don’t think it should be anything to worry about for @pilers22, but if they want, they could research and find a Custom Wait which I recall was in the DevForum

Why use a while true do loop? Just have the sound parented to the mask, Looped is on and Playing is true. This will work just fine :confused:

Not using a while true do wouldn’t work in this case since OP specifies he wants it to play a sound after 200 seconds (it could be a simple sound effect like those Accessories that make a sound). If we used Looped and Playing, it will repeatedly play the sound even if 200 seconds haven’t passed since it will the sound again when the audio has finished. This is the simplest way to achieve what he wanted, a sound that plays every 200 seconds

1 Like

Ah, my bad. I figured it was something like music that plays. I didn’t read the part about “every 200 seconds” correctly I guess :sweat_smile:

1 Like

Haha, that’s okay! Sometimes we skim through what we’re reading and forget to notice the important details. But yea, your idea would work better if it was an Accessory that played music, but he never really specified, but if made my answer as the solution, then it was most definitely just a sound effect

1 Like

exactly. I was unable to place the script in the mask accessory, as it did not work. But i ended up putting it in workspace. Maybe that would be funnier for what i am doing…i have 2 sounds, one is a background music which i renamed to BG and my sound1 (while looped) i couldnt figure out why sound isnt playing with the mask

I see, did you manage to get all working in the end? I’m not sure why the script wasn’t working in the Accessory, quite odd

i have several scripts on the last. It is supposed to be for game pass, whoever has the mask it will make a sound. It just wouldnt play. I put it “script” under the handle, and tried it as a parent of the accessory (which there already is a script) I also tried adding it the scripts to no avail

By “Already is a script” was it one of yours or did it come with the mask?

here is my explorer window

here is my script in the explorer window:

local MarketplaceService = game:GetService('MarketplaceService')

local GAMEPASSID = 15193367

local function AddHatToCharacter(Character)
	-- Run code to add hat.
	script:FindFirstChildOfClass('Accessory'):Clone().Parent = Character
end

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(Player, GamePassId, Purchased)
	if Purchased then -- They actually bought it, and didn't click 'Cancel'
		if GamePassId == GAMEPASSID then -- It's the hat gamepass
			Player.CharacterAdded:Connect(function(Character)
				AddHatToCharacter(Character)
			end)

			if Player.Character then
				AddHatToCharacter(Player.Character)
			end
		end
	end
end)

game:GetService('Players').PlayerAdded:Connect(function(Player)
	if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GAMEPASSID) then
		Player.CharacterAdded:Connect(function(Character)
			AddHatToCharacter(Character)
		end)
	end
end)

I see, is everything working though or is there another issue?

not sure if I can add the sound to the parented script. If so, where can I add it?

You can add the sound inside of the script and in the while look, just replace script.Parent.Sound with script.Sound

that could be my issue, ill try that. Thanks for your help

1 Like

Anytime! If you have anymore issues don’t be afraid to make another post!

1 Like