Why does this rotate an object?

  1. What do you want to achieve?
    I want to achieve a gate that slides when a player walks on a click detector.

  2. What is the issue?
    The issue is the object rotates when it is being tweened

  3. What solutions have you tried so far?
    I tried changing the orientation in the script, it didn’t work.

local gate = script.Parent.Union

local tweenservice = game:GetService("TweenService")

local tweeninformation = TweenInfo.new(
    0.5,
    Enum.EasingStyle.Quad,
    Enum.EasingDirection.Out,
    0,
    false,
    0
)
local gateopen = {CFrame = CFrame.new(502.001, 8.22, -1148.901)}
local gateclose = {CFrame = CFrame.new(549.001, 8.22, -1148.901)}
local tweengateopen = tweenservice:Create(gate,tweeninformation,gateopen)
local tweengateclose = tweenservice:Create(gate,tweeninformation,gateclose)

script.Parent.Detector1.Touched:Connect(function()
        tweengateopen:Play()
        wait(2)
    tweengateclose:Play()
end)

script.Parent.Detector2.Touched:Connect(function()
        tweengateopen:Play()
        wait(2)
    tweengateclose:Play()
end)

Please do not type or write the full script.
Thank you!

It’s because you’re creating a new CFrame which sets the orientation to 0, 0, 0 IIRC, you aren’t defining the orientation of the CFrame, only the position. You could either use the .Position property or use the current CFrame to create an offset CFrame.

To create the offset CFrame:

local gateopen = {CFrame = gate.CFrame} -- assuming it's open by default
local gateclosed = {CFrame = gate.CFrame * CFrame.new(47, 0, 0)} -- the offset studs (47 in your case)

Using .Position is self explanatory.

The error shows " Unable to cast to Dictionary" on line 15.

Ah whoops my bad. Just wrap it in curly brackets to make a table. Going to edit my original post.

It is still showing an error on line 15.

Double check that you’ve changed both gateopen and gateclosed to a table.

is it like this?

local gate = script.Parent.Union

local tweenservice = game:GetService("TweenService")

local tweeninformation = TweenInfo.new(
	0.5,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)
local gateopen = {gate.CFrame} -- assuming it's open by default
local gateclose = {gate.CFrame * CFrame.new(47, 0, 0)} -- the offset studs (47 in your case)
local tweengateopen = tweenservice:Create(gate,tweeninformation,gateopen)
local tweengateclose = tweenservice:Create(gate,tweeninformation,gateclose)

script.Parent.Detector1.Touched:Connect(function()
		tweengateopen:Play()
		wait(2)
	tweengateclose:Play()
end)

script.Parent.Detector2.Touched:Connect(function()
		tweengateopen:Play()
		wait(2)
	tweengateclose:Play()
end)

Yeah, both variables should be tables/dictionaries.

Line 15 the error is “Unable to cast to Dictionary”.
This line where it shows

local tweengateopen = tweenservice:Create(gate,tweeninformation,gateopen)

Oh shoot, I think it’s because I forgot to add an index.
So instead of {gate.CFrame} it should be {CFrame = gate.CFrame} on both lines. I edited my original reply.

It works! The problem is it goes to a different direction.

If it’s moving in the wrong direction, try playing around with the axes and using positive and negative numbers.

How would I do that? Would it be something to do with the “TweenInfo”?

Nah, you can just play around with the offset. Instead of gate.CFrame * CFrame.new(47, 0, 0), you’d do gate.CFrame * CFrame.new(-47, 0, 0) or gate.CFrame * CFrame.new(0, 0, 47)

Oh do you mean for the studs?

CFrame.new(47, 0, 0)

Yeah, I meant playing around with the offset.

Ok, thank you for the help I really appreciate it.

1 Like