Funny Vector3 door glitch

I’ve made a functioning door, but the way the door closes is a problem for me, it does a weird flip when I try to close the door and it’s too unrealistic for my game, also I for some reason have to double click it, for some reason it only needs to be double clicked once and then it starts to function as ussual, so if anyone could help me a tiny bit, it would be apreciated.
image

local TweenService = game:GetService("TweenService")
local ClickDetector = script.Parent.ClickDetector
local part = script.Parent
local position = script.Bool
local info = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false)
local newRotation = part.Rotation + Vector3.new(0, 90, 0)
local newPosition = part.Position + Vector3.new(3, 0, 3)
local tween = TweenService:Create(part, info, {Position = newPosition, Rotation = newRotation})
local CloseRotation = part.Rotation + Vector3.new(0, 0, 0)
local ClosePosition = part.Position + Vector3.new(0, 0, 0)
local tween2 = TweenService:Create(part, info, {Position = ClosePosition, Rotation = CloseRotation})
local Cooldown = script.Cooldown.Value

if Cooldown == false then
    ClickDetector.MouseClick:Connect(function()
        if position == false then
            tween:Play()
            position = true
            wait(2)
        else 
            tween2:Play()
            position = false
            wait(2)
        end 
    end)
end
6 Likes

switch the click detector function’s place with the if statement for the cooldown. change newRotation to Vector3.new(0,math.rad(90),0). also for the closerotation you are adding it by 0 so it wont move at all. in the tween and tween2, change position = to CFrame = CFrame.new(newPosition) * CFrame.Angles(newRotation). to fix the double click problem try changing position = script.Bool to position = false

4 Likes

Like this?
Im pretty new to coding so expect some dumb mistakes
(fixed 1 mistakes, but now doesn’t work at all)

local TweenService = game:GetService("TweenService")
local ClickDetector = script.Parent.ClickDetector
local part = script.Parent
local OpenOrClosed = script.OpenOrClosed
local info = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false)
local newRotation = part.Rotation + Vector3.new(0, math.rad(90), 0)
local newPosition = part.Position + Vector3.new(3, 0, 3)
local tween = TweenService:Create(part, info, {CFrame = CFrame.new(-31.5, 57.5, 96.5), CFrame.Angles(0, 90, 0)})
local CloseRotation = part.Rotation + Vector3.new(0, math.rad(90), 0)
local ClosePosition = part.Position + Vector3.new(0, 0, 0)
local tween2 = TweenService:Create(part, info, {CFrame = CFrame.new(-34.5, 57.5, 93.5), CFrame.Angles(0, 180, 0)})
local Cooldown = script.Cooldown.Value

ClickDetector.MouseClick:Connect(function()
	if Cooldown == false then
        if OpenOrClosed == false then
            tween:Play()
            OpenOrClosed = true
            wait(2)
        else 
            tween2:Play()
            OpenOrClosed = false
            wait(2)
        end 
    end
end)
2 Likes

to tween CFrames instead of doing cframe.new(), CFrame.Angles() you have to multiply them like CFrame.new() * CFrame.Angles(). also yeah the code seems like it could work

4 Likes

I found out what made the double click but now it’s doing a weird motion around the part it is supposed to be in.
(code if needed)

local TweenService = game:GetService("TweenService")
local ClickDetector = script.Parent.ClickDetector
local part = script.Parent
local OpenOrClosed = script.OpenOrClosed
local info = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false)
local newRotation = part.Rotation + Vector3.new(0, math.rad(90), 0)
local newPosition = part.Position + Vector3.new(3, 0, 3)
local tween = TweenService:Create(part, info, {CFrame = CFrame.new(-31.5, 57.5, 96.5) * CFrame.Angles(0, -90, 0)})
local CloseRotation = part.Rotation + Vector3.new(0, math.rad(90), 0)
local ClosePosition = part.Position + Vector3.new(0, 0, 0)
local tween2 = TweenService:Create(part, info, {CFrame = CFrame.new(-34.5, 57.5, 93.5) * CFrame.Angles(0, 0, 0)})
local Cooldown = script.Cooldown.Value

ClickDetector.MouseClick:Connect(function()
	if Cooldown == false then
		if OpenOrClosed == false then
			tween2:Play()
			OpenOrClosed = true
			wait(2)
		else 
			tween:Play()
			OpenOrClosed = false
			wait(2)
		end 
	end
end)


It’s supposed to be like this

2 Likes

change CFrame.Angles(0,-90,0) to CFrame.Angles(0,math.rad(-90),0) also if something goes wrong send a picture instead of a video cuz for some reason they arent loading (probably cuz of my device)

4 Likes

Thank you, it worked this time, I hope I didn’t waste too much of your time.

2 Likes

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