Loop and Region3 error

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

to know why this Region3 and respawn error

  1. What is the issue? Include screenshots / videos if possible!

the Region3 say i am dont in that region and the script respawn me multiple times

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

i tryed to schange the script

the script:

game.ReplicatedStorage.RemotesGames.Level1Start.OnServerEvent:Connect(function(plr, level)
	   if game.Players:FindFirstChild(plr.Name) then
	plr.Character.Head.CFrame = game.Workspace["Level 1"].TpFrame.CFrame
	local Gui = script.Parent.Level1Gui:Clone()
	Gui.Parent = game.Players[plr.Name].PlayerGui
	local Text = Gui.TextLabel
	Text.Text = "Start in 5"
	wait(1)
	Text.Text = "Start in 4"
	wait(1)
	Text.Text = "Start in 3"
	wait(1)
	Text.Text = "Start in 2"
	wait(1)	
	Text.Text = "Start in 1"
	wait(1)
	Text.Text = "Start!"
	wait(1)	
	Text.Text = "Go on the pirate hat in 10"
	wait(1)	
	Text.Text = "Go on the pirate hat in 9"
	wait(1)
	Text.Text = "Go on the pirate hat in 8"
	wait(1)	
	Text.Text = "Go on the pirate hat in 7"
	wait(1)	
	Text.Text = "Go on the pirate hat in 6"
	wait(1)	
	Text.Text = "Go on the pirate hat in 5"
	wait(1)
	Text.Text = "Go on the pirate hat in 4"
	wait(1)	
	Text.Text = "Go on the pirate hat in 3"
	wait(1)	
	Text.Text = "Go on the pirate hat in 2"
	wait(1)	
	Text.Text = "Go on the pirate hat in 1"
	wait(1)
	for i, v in pairs(game.Workspace:GetChildren()) do
	if game.Players:FindFirstChild(v.Name) then
	local c = v:FindFirstChild("Torso") or v:FindFirstChild("UpperTorso")
	local PRT = game.Workspace["Level 1"].Hat1Part
	local Region = Region3.new(PRT.Position - (PRT.Size / 2), PRT.Position + (PRT.Size / 2))
	local parts = game.Workspace:FindPartsInRegion3(Region,nil, 100000)
	for _, part in pairs(parts) do
		if part.Parent.Name == plr.Name then
			Text.Text = "Good, wait 5"	
			wait(1)
			Text.Text = "Good, wait 4"	
			wait(1)
			Text.Text = "Good, wait 3"	
			wait(1)
			Text.Text = "Good, wait 2"	
			wait(1)
			Text.Text = "Good, wait 1"	
			wait(1)
			Text.Text = "Go On The Melon-Viking Hat! in 10"	
			wait(1)
			Text.Text = "Go On The Melon-Viking Hat! in 9"	
			wait(1)	
			Text.Text = "Go On The Melon-Viking Hat! in 8"	
			wait(1)
			Text.Text = "Go On The Melon-Viking Hat! in 7"	
			wait(1)			
			Text.Text = "Go On The Melon-Viking Hat! in 6"	
			wait(1)
			Text.Text = "Go On The Melon-Viking Hat! in 5"	
			wait(1)	
			Text.Text = "Go On The Melon-Viking Hat! in 4"	
			wait(1)
			Text.Text = "Go On The Melon-Viking Hat! in 3"	
			wait(1)			
			Text.Text = "Go On The Melon-Viking Hat! in 2"	
			wait(1)	
			Text.Text = "Go On The Melon-Viking Hat! in 1"	
	for z, s in pairs(game.Workspace:GetChildren()) do
	if game.Players:FindFirstChild(s.Name) then
	local PRT2 = game.Workspace["Level 1"].Hat2Part
	local Region2C = Region3.new(PRT2.Position - (PRT2.Size / 2), PRT2.Position + (PRT2.Size / 2))
	local parts2 = game.Workspace:FindPartsInRegion3(Region2C,nil, 100000)
	for _, part2 in pairs(parts2) do
	if part2.Parent.Name == plr.Name then	
		Text.Text = "You Win!"
		plr:LoadCharacter()	
		wait(2)
		break
	else
		Text.Text = "You Lose!"	
		wait(2)
		plr:LoadCharacter()	
		break
	end				
	end
	else
	Text.Text = "You Lose!"	
	wait(2)
	plr:LoadCharacter()
	break
		end
	end
	end
	end
	end
	end
end
end)

Have you checked the entire output for any errors?

yes, it dont show anny error u get one?

This isn’t the solution to your problem, but you can really reduce the size of this script and increase the effeciency by using numerical for loops over having to set the Text one by one yourself.

Here’s an example:

for i = 10, 0, -1 do 
    --10 is the starting number, 0 is the finishing number and -1 is the increment
    Text.Text = string.format("Starting in %d", i)
    wait(1)
end
1 Like

i will try and make the script shorter but what is the bug at Region3?

Can you add a print of the PRT.Position and PRT.Size before the Region is created. This is just to confirm the input to creating the Region is valid.

i try but it shows good what to make?

I would like to see what was printed and could you add a print for the Region after its been created.

its printed the exact CFrame and Size but without this table thing {}

wait but what that %d means? can u give me a link to can learn?

%d is the string pattern for all digits, you can learn more here:

Ok good so far. what do you get in the parts table that was created by FindPartsInRegion3?
Add a print(part.Parent.Name) before the if in the for loop

Ok but i remade the script with what @return_end1 Say and now dont print nothing what to do? U want the new script?

this is my script:

game.ReplicatedStorage.RemotesGames.Level1Start.OnServerEvent:Connect(function(plr, level)
	   if game.Players:FindFirstChild(plr.Name) then
	plr.Character.Head.CFrame = game.Workspace["Level 1"].TpFrame.CFrame
	local Gui = script.Parent.Level1Gui:Clone()
	Gui.Parent = game.Players[plr.Name].PlayerGui
	local Text = Gui.TextLabel
	for i = 10,1,-1 do
		Text.Text = string.format("Game Starts in %d", i)
	    wait(1)
	end
	wait(1)
	Text.Text = "Start!"
	wait(1)	
	for i = 10, 1, -1 do
		Text.Text = string.format("Go on the Pirate Hat in %d", i)
		wait(1)
	end
	for i, v in pairs(game.Workspace:GetChildren()) do
	if game.Players:FindFirstChild(v.Name) then
	local PRT = game.Workspace["Level 1"].Hat1Part
	local Region = Region3.new(PRT.Position - (PRT.Size / 2), PRT.Position + (PRT.Size / 2))
	local parts = game.Workspace:FindPartsInRegion3(Region,nil, 100000)
	for _, part in pairs(parts) do
		if part.Parent.Name == plr.Name then
			for i = 10, 1, -1 do
				Text.Text = string.format("Good, Wait %d", i)
				wait(1)
			end
			for i = 10, 1, -1 do
				Text.Text = string.format("Go on the Melon-Viking hat in %d", i)
			    wait(1)
			end
			wait(1)
	for z, s in pairs(game.Workspace:GetChildren()) do
	local PRT2 = game.Workspace["Level 1"].Hat2Part
	local Region2C = Region3.new(PRT2.Position - (PRT2.Size / 2), PRT2.Position + (PRT2.Size / 2))
	print(PRT2.Size)
	print(PRT2.Postion)
	local parts2 = game.Workspace:FindPartsInRegion3(Region2C,nil, 100000)
	for _, part2 in pairs(parts2) do
	if part2.Parent.Name == plr.Name then	
		Text.Text = "You Win!"
		plr:LoadCharacter()	
		wait(2)
		break
	else
		Text.Text = "You Lose!"	
		wait(2)
		plr:LoadCharacter()	
		break
	end			
	end
	end
	else
	Text.Text = "You Lose!"	
	wait(2)
	plr:LoadCharacter()
	break
		end
		end
	end
	end
	end
end)

i remake the script but the part 2 dont works, and it prints something like: table:4324ze32zz23x
script:

game.ReplicatedStorage.RemotesGames.Level1Start.OnServerEvent:Connect(function(plr, level)
	   if game.Players:FindFirstChild(plr.Name) then
	plr.Character.Head.CFrame = game.Workspace["Level 1"].TpFrame.CFrame
	local Gui = script.Parent.Level1Gui:Clone()
	Gui.Parent = game.Players[plr.Name].PlayerGui
	local Text = Gui.TextLabel
	for i = 10,1,-1 do
		Text.Text = string.format("Game Starts in %d", i)
	    wait(1)
	end
	wait(1)
	Text.Text = "Start!"
	wait(1)	
	for i = 10, 1, -1 do
		Text.Text = string.format("Go on the Pirate Hat in %d", i)
		wait(1)
	end
	for i, v in pairs(game.Workspace:GetChildren()) do
	if game.Players:FindFirstChild(v.Name) then
	local PRT = game.Workspace["Level 1"].Hat1Part
	local Region = Region3.new(PRT.Position - (PRT.Size / 2), PRT.Position + (PRT.Size / 2))
	local parts = game.Workspace:FindPartsInRegion3WithIgnoreList(Region,{game.Workspace["Level 1"]}, 100000)
	for _, part in pairs(parts) do
		if part.Parent.Name == plr.Name then
			for i = 10, 1, -1 do
				Text.Text = string.format("Good, Wait %d", i)
				wait(1)
			end
			for i = 10, 1, -1 do
				Text.Text = string.format("Go on the Melon-Viking hat in %d", i)
			    wait(1)
			end
	for z, s in pairs(game.Workspace:GetChildren()) do
	local PRT2 = game.Workspace["Level 1"].Hat2Part
	local Region2C = Region3.new(PRT2.Position - (PRT2.Size / 2), PRT2.Position + (PRT2.Size / 2))
	local parts2 = game.Workspace:FindPartsInRegion3WithIgnoreList(Region2C,{game.Workspace["Level 1"]}, 100000)
	for c, part2 in pairs(parts2) do
	if part2.Parent.Name == plr.Name then	
		Text.Text = "You Win!"
		plr:LoadCharacter()	
		wait(2)
		break
	else
		Text.Text = "You Lose!"	
		wait(2)
		plr:LoadCharacter()	
		break
	end			
	end
	end
	else
	Text.Text = "You Lose!"	
	wait(2)
	plr:LoadCharacter()
	break
		end
		end
	end
	end
	end
end)

Include this in your script before the for loop that iterates through what’s in the Region3:

print(unpack(parts))

This prints all parts that are in the table returned by the function. This would probably help in debugging

I will try to see what îs the Error

i make it to work, thanks you!