Tweening model script is acting weird

I am trying to create a script that makes a sliding door effect however it is acting faulty even the code looks fine, at least to me.

As you can see when I step close to the doors (using a hidden and transparent part to detect the movement), the tween does not immediately play, instead for some reason it waits for a few couple of seconds before tweening and the tweening goals are wrong. Not only that, it doesn’t tween the entire model of the sliding door models. Can someone help? Thanks!

local TweenService = game:GetService("TweenService")

local model = script.Parent
local detector = model.Detector
local leftSlidingDoor = model.LeftSlidingDoor
local rightSlidingDoor = model.RightSlidingDoor

local tweenInfo = TweenInfo.new(
	1,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	0,
	true,
	5
)
local leftTweenGoal = {
	CFrame = CFrame.new(-44.8, 4.25, 29.95)
}
local rightTweenGoal = {
	CFrame = CFrame.new(-44.8, 4.25, 9.95)
}

local debounce = false

local function onPartTouched(hit)
	local model = hit:FindFirstAncestorWhichIsA("Model")
	if model:FindFirstChildWhichIsA("Humanoid") and not debounce then
		debounce = true
		print("GO")
		local leftDoorTween = TweenService:Create(leftSlidingDoor.PrimaryPart, tweenInfo, leftTweenGoal)
		local rightDoorTween = TweenService:Create(rightSlidingDoor.PrimaryPart, tweenInfo, rightTweenGoal)
		leftDoorTween:Play()
		print("playing")
		rightDoorTween:Play()
		leftDoorTween.Completed:Wait()
		rightDoorTween.Completed:Wait()
		print("done") -- sometimes this never gets to fired if i move my character within the detector part
		debounce = false
	end
end

detector.Touched:Connect(onPartTouched)
1 Like

Your problem is located here:


local leftTweenGoal = {
	CFrame = CFrame.new(-44.8, 4.25, 29.95)
}
local rightTweenGoal = {
	CFrame = CFrame.new(-44.8, 4.25, 9.95)
}

CFrame has orientation as its second vector3 value.
If you’re not setting the orientation then it’ll be 0,0,0.

In your case, the door is probably not oriented with 0,0,0. Therefore, it’ll move around in the wrong direction.

You’ll need to add a direction but there’s an easier method.

Instead of tweening the CFrame, tween its position. The position won’t change the orientation which in this case is what you need.

local leftTweenGoal = {
	Position = Vector3.new(-44.8, 4.25, 29.95)
}
local rightTweenGoal = {
	Position = Vector3.new(-44.8, 4.25, 9.95)
}

If you want to still use CFrame then you can use this:

local leftTweenGoal = {
	CFrame = CFrame.new(Vector3.new(-44.8, 4.25, 29.95), object.CFrame.LookVector * 2)
}
local rightTweenGoal = {
	CFrame = CFrame.new(Vector3.new(-44.8, 4.25, 29.95), object.CFrame.LookVector * 2)
}
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.