What do you want to achieve?
I want to achieve a gate that slides when a player walks on a click detector.
What is the issue?
The issue is the object rotates when it is being tweened
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!
7z99
(cody)
February 19, 2021, 10:20pm
2
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.
7z99
(cody)
February 19, 2021, 10:24pm
4
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.
7z99
(cody)
February 19, 2021, 10:30pm
6
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)
7z99
(cody)
February 19, 2021, 10:32pm
8
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)
7z99
(cody)
February 19, 2021, 10:36pm
10
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.
7z99
(cody)
February 19, 2021, 10:40pm
12
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”?
7z99
(cody)
February 19, 2021, 10:42pm
14
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)
7z99
(cody)
February 19, 2021, 10:43pm
16
Yeah, I meant playing around with the offset.
Ok, thank you for the help I really appreciate it.
1 Like