Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Tweening a parts position with Vector3 "Unable to cast to Dictionary"? [Update]

Asked by 7 years ago
Edited 7 years ago

I have a sliding door basically and I wanted it to open and all that jazz and I want to to open using Vector3 instead of CFrames

Heres the script, lines 9 - 12 are where you would tell it to move, I had CFrames there but I removed them because Id rather use Vector3 it would be easier. I just dont know how Id go about doing this?

local TweenService = game:GetService("TweenService")

local leftdoor = script.Parent:WaitForChild("LeftDoor")
local rightdoor = script.Parent:WaitForChild("RightDoor")

local tweeiningInformation = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)

local leftdoorOpen = Vector3.new(0,5,0)
local rightdoorOpen = Vector3.new(0,5,0)
local leftdoorClosed = Vector3.new(0,0,0)
local rightdoorClosed = Vector3.new(0,0,0)
local tween1Open = TweenService:Create(leftdoor, tweeiningInformation, leftdoorOpen)
local tween1Closed = TweenService:Create(leftdoor, tweeiningInformation, leftdoorClosed)
local tween2Open = TweenService:Create(rightdoor, tweeiningInformation, rightdoorOpen)
local tween2Closed = TweenService:Create(rightdoor, tweeiningInformation, rightdoorClosed)

script.Parent.HitDetector1.Touched.Connect(function(hit)
    tween1Open:Play()
    tween2Open:Play()
    wait(3)
    tween1Closed:Play()
    tween2Closed:Play()
end)

script.Parent.HitDetector2.Touched.Connect(function(hit)
    tween1Open:Play()
    tween2Open:Play()
    wait(3)
    tween1Closed:Play()
    tween2Closed:Play()
end)

So I attemped some Vector3 stuff and I got the weirdest error ever?

It errors "Unable to cast to Dictionary"

Thanks for your time.

0
The last argument of Create needs to be a dictionary of things to tween ie {Position = Vector3.new(0,5,0)} User#5423 17 — 7y
0
What do you mean? Is there a wiki or a better example? GottaHaveAFunTime 218 — 7y
0
Yes there is a wiki page on it with a example http://wiki.roblox.com/index.php?title=API:Class/TweenService User#5423 17 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Your problem here is that you are trying to use a Vector 3 on a function expecting a CFrame.You also have to turn it into a table

If you want to use a Vector3 in a CFrame you can do:

local leftdoorOpen = { CFrame.new(0,5,0) }
-- If the door is rotated the wrong way do: 
-- local leftdoorOpen = { CFrame.new(0,5,0) * CFrame.Angles(0,0,0) } -- replace a 0 with math.pi or math.pi /2 for half a turn or math.pi/4 for a quarter of a turn and so on...

--To automatically adjust the position of the doors opening to fit any location you can do:
--local leftdoorOpen = { CFrame.new(DoorNameHere.Position - DoorNameHere.CFrame.rightVector * OFFSET)
--Do exactly the same for the opposite door but negate the value to make it go to the left assuming their right side is the same direction on both doors

Finally you should check the wiki out. http://wiki.roblox.com/index.php?title=CFrame

It may be hard to understand but once you do it will be your best friend.

Keep in mind that i haven't tested this exact piece of code. Though i've done it using that method for a sliding door of mine which seems to be what you are trying to create. If you run into any errors/problems you can't solve. I'll gladly help you.

-ScrappyHaxor

0
wrong answer creeperhunter76 554 — 7y
0
How is that a wrong answer? Please provide more. I'm looking to improve. ScrappyHaxor 8 — 7y
Ad

Answer this question