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

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

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

1 comment

0

Code block please

1 answer

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

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