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

Need help using region3 method using a online tutorial?

I followed tutorials online and followed them exactly but it doesn’t work? Can u guys help?

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

local Found = false

while wait(1) do

view source

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

error in code: for_, part in pairs(parts) do

1 comment

0

Try putting a space between 'for' and '_'. I'm fairly sure the 'for' operator needs to be blue, otherwise Lua doesn't recognize it.

1 answer

So you have several mistakes in this script. First off, on line 21 where Found = true, it's actually supposed to be Found == true. The second mistake is the one that Abandion said. Line 9 is supposed to be: for _, part in pairs(parts) do

The whole code correctly would be:

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 = workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())
		
		for _, part in pairs(parts) do
			if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then
				Found = true
				break
			else
				Found = false
			end
		end
		
		if Found == true then
			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

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