Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 1 year ago

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

Log in to vote
0
Answered by
VAnkata20 135
1 year ago

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

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. Stiles8353 35 — 1y
0
I'm assuming this is because it's a local script, and resets upon death. Stiles8353 35 — 1y
0
Alright imnotaguest1121 362 — 1y
0
That can be easily done with few changes VAnkata20 135 — 1y
Ad

Answer this question