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

Unable to cast to dictionary error fix?

Asked by
MediaHQ 53
3 years ago
Edited 3 years 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 3 years ago
Edited 3 years 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) User#30567 0 — 3y
0
For line 6 & 7, OP wanted the CFrame to be "door.CFrame + CFrame.new", not "door.CFrame * CFrame.new" User#30567 0 — 3y
0
sorry I was on mobile XD LinavolicaDev 570 — 3y
0
Btw there is no CFrame + CFrame metamethod field in the CFrame metatable class. LinavolicaDev 570 — 3y
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 53 — 3y
0
So change it from Y to X... I didn't know your original idea XD LinavolicaDev 570 — 3y
Ad

Answer this question