Hello there,
I am trying to develop a door that opens automatically when someone is approaching and that closes automatically when no one is near.
I made the detection with .Touched event and .TouchEnded event. Each time a Humanoid touches the hitbox, it’ll insert its name in a table, and if it leaves, it’ll remove it. So I detect how many people are near the door to make it open by using #touching
, that returns the number of names indexed in the latter table.
Now, I need to make the door move. Note that I’d like, if possible to make it move using EasingStyle and EasingDirection.
I tried TweenService
but the problem is that the model is containing several children and it moves the primaryPart only. I wanted to associate that with model:SetPrimaryPartCFrame(basepart.CFrame)
but the elements in the model were not following.
I intended to use Vector3():Lerp
but it did not work either. (Yes I am dumb with these methods…)
Here is a sample of the whole code:
local TService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0)
local doorMainPart = script.Parent.doorModel.PrimaryPart
local tween = TService:Create(doorMainPart, tweenInfo, {Position = Vector3.new(doorMainPart.Position.X - doorMainPart.Size.X, doorMainPart.Position.Y, doorMainPart.Position.Z)})
tween:Play()
for i = 0, 60, 1 do
wait(.01)
doorMainPart.Parent:SetPrimaryPartCFrame(doorMainPart.CFrame)
end
Here is an explorer screen of the door: https://gyazo.com/363eaa6dd1c17c7b947f38bc988bd4ce
-
This method is not working ._.
-
As I am based on the X Axis when moving the door, it’ll work properly only if the
PrimaryPart
(and at the same time the whole door) is goodly oriented. If we rotate it only at 90°, the door would just do something weird… (Should I useCFrame.lookVector
method ?)
If you don’t understand anything, please let a post, I can do some screenshots to make you understand better.
Thank you for trying to help me !