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
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