EDIT: I created a repo file so you can reproduce the error yourself and hopefully it will be easier for you to figure out what the issue is. Thanks again for helping me out! ErrorRepo.rbxl (31.4 KB)
Please copy and paste the code in the code format as a reply so I can view it better.
Judging by what I can see, I suggest you use a click-detector, and not a value or whatever you’re using to open it, as you can set the max activation distance to 0 to make it un-clickable while it’s running.
Also, you use a wait() function after the opening sequence, but for the closing sequence you use a function that waits for the sequence to finish. It may be that.
And that code clearly isn’t yours, as it has the comments after the TweenInfo line.
What I would suggest is trying other tutorials if you are following them, as they will have different answers/code to this.
I can’t find a reason to this, as I can’t run it myself.
Try hovering over the code, maybe something is missing? Also, check the console if anything shows up.
local TweenService = game:GetService("TweenService")
local Door = script.Parent.Door
local DoorRoot = Door.PrimaryPart
local toggle = false
function openDoor()
if toggle == false then
toggle = true
local DoorSlideInfo = TweenInfo.new() -- Let's use all defaults here
local DoorSlideOpenTween = TweenService:Create(DoorRoot, DoorSlideInfo, {
CFrame = DoorRoot.CFrame * CFrame.new(DoorRoot.Size.X + 4.5, 0, 0)
})
DoorSlideOpenTween:Play()
wait(4)
local DoorSlideInfo = TweenInfo.new() -- Let's use all defaults here
local DoorSlideCloseTween = TweenService:Create(DoorRoot, DoorSlideInfo, {
CFrame = DoorRoot.CFrame * CFrame.new(DoorRoot.Size.X - 4.5, 0, 0)
})
DoorSlideCloseTween:Play()
DoorSlideCloseTween.Completed:Wait()
toggle = false
end
end
Door.ClickDetector.MouseClick:Connect(openDoor)
In the output it returns these two sets of values. The first one is the CFrame of the RootPart after the OpenTween. The second one is the CFrame of the RootPart after the CloseTween.
Well you clearly have to use Vector3…
I don’t really know what else to do…
Have you tried using the PrimaryRootPart for the door model and not the root attached to the door?
I used it as I heard it was the most efficient method of tweening a model according to an article. If you want to see the error for yourself I’ve attached a file where you can reproduce it.
Using a part’s size to find out the size of the gap after the first click, I added it to the 4.5 in the closing sequence, and I am fine tuning it right now to make sure there is no gap. I will message again with the correct number.
local TweenService = game:GetService("TweenService")
local Door = script.Parent.Door
local DoorRoot = Door.PrimaryPart
local toggle = false
function openDoor()
if toggle == false then
toggle = true
local DoorSlideInfo = TweenInfo.new()
local DoorSlideOpenTween = TweenService:Create(DoorRoot, DoorSlideInfo, {
CFrame = DoorRoot.CFrame * CFrame.new(DoorRoot.Size.X + 4.5, 0, 0)
})
DoorSlideOpenTween:Play()
DoorSlideOpenTween.Completed:Wait()
print(DoorRoot.CFrame)
wait(4)
local DoorSlideInfo = TweenInfo.new()
local DoorSlideCloseTween = TweenService:Create(DoorRoot, DoorSlideInfo, {
CFrame = DoorRoot.CFrame * CFrame.new(DoorRoot.Size.X - 4.93, 0, 0) -- Exact number for no gap.
})
DoorSlideCloseTween:Play()
DoorSlideCloseTween.Completed:Wait()
print(DoorRoot.CFrame)
toggle = false
end
end
Door.ClickDetector.MouseClick:Connect(openDoor)
I know that the matter has been resolved, but I would like to point out that the code uses DoorRoot.Size.X when trying to transpose the door 4.5 studs in a certain direction.
If you wished to transpose the door 4.5 studs in a certain direction, relative to the rotation of the door, then might I suggest using removing the DoorRoot.Size.X from the code altogether and replacing the -4.93 with -4.5.