Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I make sound regions pause and resume instead of restarting everytime you enter it?

This is AlvinBlox's SoundRegion script, and I edited it a bit to try and make the music pause and resume, yet it still just restarts when you re enter the area. Can someone help find where the error is?

local SoundRegionsWorkspace = game.Workspace:WaitForChild("SoundRegions")

local Found = false

while true do

	for i, v in pairs (SoundRegionsWorkspace:GetChildren()) do

		Found = false
		local region = Region3.new(v.Position - (v.Size/2),v.Position + (v.Size/2))

		local parts = game.Workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())


		for _, part in pairs(parts) do
			-- Loop one by one through the parts table
			if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then
				Found = true
				break
			else
				Found = false
			end
		end

		if Found == true then -- from here down is where i edited it to try and fix it for my purposes
			-- Start playing some music
			if script.Parent.SoundRegions[v.Name].IsPaused == true then
				script.Parent.SoundRegions[v.Name]:Resume() 
				break
			end
		else
			script.Parent.SoundRegions[v.Name]:Pause()
		end

	end
	wait(.1)
end

1 answer

✓ Accepted answer

I have tried this and it appears to be working

local SoundRegionsWorkspace = game.Workspace:WaitForChild("SoundRegions")

local Found = false

while wait(0) do

	for i, v in pairs (SoundRegionsWorkspace:GetChildren()) do

		Found = false
		local region = Region3.new(v.Position - (v.Size/2),v.Position + (v.Size/2))

		local parts = game.Workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())


		for _, part in pairs(parts) do
			-- Loop one by one through the parts table
			if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then
				print("Player was found")
				Found = true
				break
			else
				Found = false
				print("Player was not found in region")
			end
		end

		if Found == true then
			-- Start playing some music
			if script.Parent.SoundRegions[v.Name].IsPlaying == false then
				script.Parent.SoundRegions[v.Name]:Resume()
				break
			end
		else
			script.Parent.SoundRegions[v.Name]:Pause()
		end

	end
end

Tell me if it dosent work or if it gives out an error

4 comments

0

Yeah now that I look at it I saw what was wrong and I feel kind of stupid for not seeing it before, it works, but I found another problem where dying resets the timeposition on the sound.

0

I'm assuming this is because it's a local script, and resets upon death.

0

Alright

0

That can be easily done with few changes

This discussion is preserved as it was. New answers, comments, and votes are closed.