I’m currently running into a problem making a few sliding doors not tween and throw an error. First off, I got the main body of this from an AlvinBlox video, the script was super outdated so I updated it to not throw any errors in the script analysis; however, I’m now facing a “Unable to cast to Dictionary” error whenever I load the game.
I looked it up on the Devforum and Developer Wiki and it seems that the simple fix is to change the first bit of all of the TweenService:Create() to an instance… but according to the developer wiki on instance, “WaitForChild” makes my first variables all instances. I’m at a loss on how to solve this issue and/or improve my code. I’ve pasted everything I have here if someone wouldn’t mind helping me out.
local TweenService = game:GetService("TweenService")
local d1 = script.Parent.SlidingDoor1:WaitForChild("Glass")
local d2 = script.Parent.SlidingDoor2:WaitForChild("Glass")
local tweeningInfo = TweenInfo.new(
0.25,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local detectorPart = script.Parent:WaitForChild("Detector")
local d1Open
local d2Open
local d1Close
local d2Close
if detectorPart.Orientation == Vector3.new(0, 90, 0) or detectorPart.Orientation == Vector3.new(0, -90, 0) or detectorPart.Orientation == Vector3.new(0, 270, 0) or detectorPart.Orientation == Vector3.new(0, -270, 0) then
d1Open = CFrame.new(d1.Position-Vector3.new(4.25,0,0))
d2Open = CFrame.new(d1.Position+Vector3.new(4.25,0,0))
d1Close = CFrame.new(d1.Position)
d2Close = CFrame.new(d2.Position)
else
d1Open = CFrame.new(d1.Position-Vector3.new(0,0,4.25))
d2Open = CFrame.new(d1.Position+Vector3.new(0,0,4.25))
d1Close = CFrame.new(d1.Position)
d2Close = CFrame.new(d2.Position)
end
local tween1open = TweenService:Create(d1,tweeningInfo,d1Open)
local tween1close = TweenService:Create(d1,tweeningInfo,d1Close)
local tween2open = TweenService:Create(d2,tweeningInfo,d2Open)
local tween2close = TweenService:Create(d2,tweeningInfo,d2Close)
script.Parent.Detector.Touched:Connect(function(hit)
tween1open:Play()
tween2open:Play()
wait(3)
if hit == true then
return
end
tween1close:Play()
tween2close:Play()
end)
Thank you very much