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

'Unable to Cast to Dictionary' When Tween Service is Used?

I'm trying to make a door sliding script that uses tween service to move the door. But when I do use it, the output says it's unable to cast to dictionary. How could I fix this? Thanks.

local goal = script.Parent.Door.Position + Vector3.new(1,0,0)

local function DoorAnim ()
	local TweenService = game:GetService("TweenService")
	local tweenInfo = TweenInfo.new(5)
 
local tween = TweenService:Create(script.Parent.Door, tweenInfo, goal)

tween:Play()
end

script.Parent.Model.Part1.SurfaceGui.TextButton.MouseButton1Down:Connect(function()
		DoorAnim()
end)

1 answer

✓ Accepted answer

The problem is that your goal variable is a Vector3 type. It should be a dictionary, with the keys being the properties you want to change and the values being the new values of those properties.

local goal = {
	Position = script.Parent.Door.Position + Vector3.new(1, 0, 0)
}

local function DoorAnim ()
    local TweenService = game:GetService("TweenService")
    local tweenInfo = TweenInfo.new(5)

	local tween = TweenService:Create(script.Parent.Door, tweenInfo, goal)
	
	tween:Play()
end

script.Parent.Model.Part1.SurfaceGui.TextButton.MouseButton1Down:Connect(function()
        DoorAnim()
end)

Hope this helps! :)

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