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)