Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Unable to cast to dictionary error fix?

Asked by
MediaHQ 36
8 days ago
Edited 8 days ago

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

Log in to vote
-1
Answered by 8 days ago
Edited 7 days ago

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

0
Two things, OP made a mistake on line 10 (he put TweenService as the second argument) TTChaos 731 — 8d
0
For line 6 & 7, OP wanted the CFrame to be "door.CFrame + CFrame.new", not "door.CFrame * CFrame.new" TTChaos 731 — 8d
0
sorry I was on mobile XD LinavolicaDev 540 — 8d
0
Btw there is no CFrame + CFrame metamethod field in the CFrame metatable class. LinavolicaDev 540 — 8d
View all comments (2 more)
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 MediaHQ 36 — 7d
0
So change it from Y to X... I didn't know your original idea XD LinavolicaDev 540 — 7d
Ad

Answer this question