Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Unable to cast to dictionary error fix?

Trying to make an open and close door but it gives me an error saying "Unable to cast to dictionary"

local door = game.Workspace.Door

local TweenService = game:GetService("TweenService")
local TweenStyle = TweenInfo.new(0.5,Enum.EasingStyle.Quad)

local dooropen = (door.CFrame + Vector3.new(0, 10, 0))
local doorclose = (door.CFrame + Vector3.new(0, -10, 0))

local doortween = TweenService:Create(door,TweenStyle,doorclose)
local closedoortween = TweenService:Create(door,TweenService,dooropen)

script.Parent.ClickDetector.MouseClick:Connect(function()
	doortween:Play()
	wait(5)
	closedoortween:Play()
end)

Does anyone know how to fix it? Edit: The error is on line 9

1 answer

You need a dictionary to indicate the value of the given attribute. So change your code to this:

local door = game.Workspace.Door

local TweenService = game:GetService("TweenService")
local TweenStyle = TweenInfo.new(0.5,Enum.EasingStyle.Quad)

local dooropen = {CFrame = door.CFrame * CFrame.new(10, 0, 0)}
local doorclose = {CFrame = door.CFrame * CFrame.new(-10, 0, 0)}

local doortween = TweenService:Create(door,TweenStyle,doorclose)
local closedoortween = TweenService:Create(door,TweenStyle ,dooropen)

script.Parent.ClickDetector.MouseClick:Connect(function()
    doortween:Play()
    wait(5)
    closedoortween:Play()
end)

API-REFERENCE

6 comments

0

Two things, OP made a mistake on line 10 (he put TweenService as the second argument)

0

For line 6 & 7, OP wanted the CFrame to be "door.CFrame + CFrame.new", not "door.CFrame * CFrame.new"

0

sorry I was on mobile XD

0

Btw there is no CFrame + CFrame metamethod field in the CFrame metatable class.

0

This does work, but it doesn't slide the door up it slides it down then up and it doesn't even close properly

0

So change it from Y to X... I didn't know your original idea XD

This discussion is preserved as it was. New answers, comments, and votes are closed.