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

How do I make this script play music like it's supposed to?

Asked by
Tyler8D -5
5 years ago

Can someone help me figure out what's wrong with my script? I have tried to fix it several times. It's supposed to play music when you walk into specific areas. I followed this tutorial exactly. https://www.youtube.com/watch?v=L_Jga2MgRdU local SoundRegionsWorkspace = game.Workspace:WaitForChild("SoundRegions") local Found = false while wait(1) 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]:play() break end else script.Parent.SoundRegions[v.Name]:Stop() end end end

0
Code block please SuperSamyGamer 316 — 5y

1 answer

Log in to vote
0
Answered by
sheepposu 561 Moderation Voter
5 years ago
Edited 5 years ago

Not an answer - posting code block for them

local SoundRegionsWorkspace = game.Workspace:WaitForChild(“SoundRegions”) local Found = false 

while wait(1) 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]:play() 
                break 
            end 
        else 
            script.Parent.SoundRegions[v.Name]:Stop() 
        end 
    end 
end

Tell me if I put it together incorrectly

Ad

Answer this question