Region3 seriously not working

Hello everyone, yesterday, I’ve been working on a script that uses a Region3 to make a building tween its CFrame, so it can be animated coming out of the ground (The tween I’ve got down, so that’s not the problem) but the process of which it fires such tween, is just not working.

The only script, and its a server script in the model:

local region = Region3.new(script.Parent.Range.Position - (script.Parent.Range.Size / 2),script.Parent.Range.Position + (script.Parent.Range.Size / 2))
local Leader = {}
-- You can ignore the variables from down here, they're the variables dealing with the tween, so they can't be part of the issue
local Hinge = script.Parent.Hinge
local Hinge2 = script.Parent.Hinge2
local Tesla = script.Parent.Base
local TS = game:GetService("TweenService")
local HingeStyle = TweenInfo.new(.5,Enum.EasingStyle.Bounce,Enum.EasingDirection.Out,0,false,0)
local HingeStyle2 = TweenInfo.new(1,Enum.EasingStyle.Exponential,Enum.EasingDirection.In,0,false,0)
local TeslaStyle = TweenInfo.new(1,Enum.EasingStyle.Exponential,Enum.EasingDirection.In,0,false,0)
local HingeGoal = {CFrame = Hinge.CFrame * CFrame.new(0,0,0) * CFrame.Angles(0,0,math.rad(-100))}
local HingeGoal2 = {CFrame = Hinge2.CFrame * CFrame.new(0,0,0) * CFrame.Angles(0,0,math.rad(100))}
local HingeReturn = {CFrame = Hinge.CFrame * CFrame.new(0,0,0) * CFrame.Angles(0,0,math.rad(0))}
local HingeReturn2 = {CFrame = Hinge2.CFrame * CFrame.new(0,0,0) * CFrame.Angles(0,0,math.rad(0))}
local TeslaGoal = {CFrame = Tesla.CFrame * CFrame.new(0,29,0) * CFrame.Angles(0,0,0)}
local TeslaReturn = {CFrame = Tesla.CFrame * CFrame.new(0,0,0) * CFrame.Angles(0,0,0)}

while wait(.5) do -- I'm waiting 0.5 seconds since going any lower lags the game, and that's no good, but tell me if I can go lower after the solution
	local partsInRegion = workspace:FindPartsInRegion3(region,nil,1000)
	for _, part in pairs(partsInRegion) do
		local plr = game.Players:FindFirstChild(part.Parent.Name)
		table.insert(Leader,plr)
		if table.find(Leader,plr) then
			local Open1 = TS:Create(Hinge,HingeStyle,HingeGoal)
			local Open2 = TS:Create(Hinge2,HingeStyle,HingeGoal2)
			local Rise = TS:Create(Tesla,TeslaStyle,TeslaGoal)
			Open1:Play()
			Open2:Play()
			Rise:Play()
			print("rising")
		elseif table.find(Leader,plr) == nil then
			Leader = {}
			local Close1 = TS:Create(Hinge,HingeStyle2,HingeReturn)
			local Close2 = TS:Create(Hinge2,HingeStyle2,HingeReturn2)
			local Drop = TS:Create(Tesla,TeslaStyle,TeslaReturn)
			Close1:Play()
			Close2:Play()
			Drop:Play()
			print("dropping")
		end
	end
end

The problem, is that I want the script to constantly check if a player is within such region, but it keeps saying “dropping”, and “rising”:

I just want it to say “Rising” when the player is inside

I’ve tried changing the position of the wait() and its wait time, I’ve tried changing the second parameter in the :FindPartsInRegion3() to the actual Tesla model, and also the third parameter to a higher and lower number. I’ve also tried not using a table, renaming the variables, but to no avail, it just keep printing “Rising” and “Dropping” over and over. I’ve made sure to set all the variables correctly, in the model and the variables of the script. No spelling errors, no script errors. I’ve even tried eliminating the numbers within the wait() leaving only the wait itself. Obviously, it lagged hard

The region variable is set the range parts corners because the building can be moved, so if that’s the problem, please tell me.

No need to send me links to other forums with the same or similar issues, I’ve already read them all, and they didn’t fix anything :sob: I also checked out some tutorials on the internet, and nothing. :sob: x2

What shall I do meh fellow dev’s?

  1. Maybe its too obvius but did you tried use RotatedRegion3 from EgoMoose?
  2. try to do
local plr = game.Players:GetPlayerFromCharacter(part.Parent)
  1. Honestly idk, it doesnt looks so wrong.

Rotated Region3, ok I’ll take a look into it. Right after I use:

local plr = game.Players:GetPlayerFromChracter(part.Parent)

About Region3 and RotatedRegion3
Region3 its a “box” with only 1 rotation and phew functions.
RotatedRegion3 allows you use any shape of region, rotated them as you want, change CFrame/Size when you want and etc.

EDIT: oh also its :GetPlayerFromCharacter(part.Parent)
:GetPlayerFromCharacter()
RotatedRegion3 by EgoMoose

1 Like

Alright, responding at this hour since it was night yesterday.
Anyway, I tried changing the plr to :GetPlayerFromCharacter(), but it did not work :sad:.

local plr = game.Players:GetPlayerFromCharacter(part.Parent)

I’ve also checked out the RotatedRegion3 forum you’ve shown me, but I’m actually quite confused on how to set it up and make it work. How do I do it?

local region = RotatedRegion3.new(SomeCFrame,SomeSize)
local parts = region:FindPartsInRegion3()
for i,v in pairs(parts) do 
print(v)
end

I see (sry for responding now, was busy with other things)
Ok, and this goes in another server script, or within one of the module scripts?