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 insideI’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 I also checked out some tutorials on the internet, and nothing. x2
What shall I do meh fellow dev’s?