Unable to cast to Dictionary error

Hello,

So when I tested my script I got this error “Unable to cast to dictionary” on line 24 and 25 and I don’t know how to fix it can someone help me?

local TweenService = game:GetService("TweenService")

local textbutton = script.Parent.Parent["A-Chassis Tune"].Plugins.AC6_Stock_Gauges.OpenBusDoors

-- Create the RemoteEvent
local remoteEvent = Instance.new("RemoteEvent")
remoteEvent.Name = "DoorRequestEvent"
remoteEvent.Parent = game.ReplicatedStorage
print("The Remote event was made")

timeout_number = 6

local remoteEvent = game.ReplicatedStorage:WaitForChild("DoorRequestEvent", timeout_number)

-- Function to handle the door movement
local function handleDoorRequest(player, doorOpen)
	local LeftBusDoor = script.Parent.BusDoors.LeftBusDoor.LeftDoor
	local RightBusDoor = script.Parent.BusDoors.RightBusDoor.RightDoor
	print("Found the Bus doors")

	local openPosition = Vector3.new(0, 5, 0) 
	local closedPosition = Vector3.new(0, 0, 0) 
	local tweenInfo  = TweenInfo.new(1)
	local tweenOpen = TweenService:Create(LeftBusDoor, RightBusDoor, tweenInfo, openPosition)
	local tweenClose = TweenService:Create(RightBusDoor, LeftBusDoor, tweenInfo, closedPosition)

	-- Move the doors based on the doorOpen parameter
	if doorOpen then
		tweenOpen:Play()
		textbutton.Text = "Open Bus Doors"
		print("Door Opened")
	else
		tweenClose:Play()
		textbutton.Text = "Close Bus Doors"
		print("Door Closed")
	end
end

-- Event listener for handling door requests
remoteEvent.OnServerEvent:Connect(handleDoorRequest)

textbutton.Activated:Connect(handleDoorRequest())

There are only 3 arguments you can pass in TweenService:Create, Instance, TweenInfo, propertyTable. You cannot pass more than one Instance through TweenService:Create().

Here is your updated code:

local TweenService = game:GetService("TweenService")

local textbutton = script.Parent.Parent["A-Chassis Tune"].Plugins.AC6_Stock_Gauges.OpenBusDoors

-- Create the RemoteEvent
local remoteEvent = Instance.new("RemoteEvent")
remoteEvent.Name = "DoorRequestEvent"
remoteEvent.Parent = game.ReplicatedStorage
print("The Remote event was made")

timeout_number = 6

local remoteEvent = game.ReplicatedStorage:WaitForChild("DoorRequestEvent", timeout_number)

-- Function to handle the door movement
local function handleDoorRequest(player, doorOpen)
	local LeftBusDoor = script.Parent.BusDoors.LeftBusDoor.LeftDoor
	local RightBusDoor = script.Parent.BusDoors.RightBusDoor.RightDoor
	print("Found the Bus doors")

	local openPosition = Vector3.new(0, 5, 0) -- Replace with the desired open position
	local closedPosition = Vector3.new(0, 0, 0) -- Replace with the desired closed position
	local tweenInfo  = TweenInfo.new(1)
	
	-- Left and Right tweens for both 'Open' and 'Close'
	local tweenLeftOpen = TweenService:Create(LeftBusDoor, tweenInfo, {Position = openPosition})
	local tweenRightOpen = TweenService:Create(RightBusDoor, tweenInfo, {Position = openPosition})
	
	local tweenLeftClose = TweenService:Create(LeftBusDoor, tweenInfo, {Position = closedPosition})
	local tweenRightClose = TweenService:Create(RightBusDoor, tweenInfo, {Position = closedPosition)
	
	-- Move the doors based on the doorOpen parameter
	if doorOpen then
		tweenLeftOpen:Play()
		tweenRightOpen:Play()
		
		textbutton.Text = "Open Bus Doors"
		print("Door Opened")
	else
		tweenLeftClose:Play()
		tweenRightClose:Play()
		
		textbutton.Text = "Close Bus Doors"
		print("Door Closed")
	end
end

-- Event listener for handling door requests
remoteEvent.OnServerEvent:Connect(handleDoorRequest)

textbutton.Activated:Connect(handleDoorRequest())
1 Like

wait i still got the error unable to cast to dictionary i just tested it

Apart from this issue, you need to pass a dictionary where each key is the property name and the value is the desired goal value. For example:

{ Position = openPosition }
1 Like

uhh im still getting the error…

As what @D1CEL said, you need to have a property name and target value (in a table) for the third argument of the tweens. It appears you are attempting to change the position of the doors, so you’d do something like what @D1CEL showed above.
You could also create a table and add/insert the property values to use for the target goal value when tweening.

Updated Code:

local TweenService = game:GetService("TweenService")

local textbutton = script.Parent.Parent["A-Chassis Tune"].Plugins.AC6_Stock_Gauges.OpenBusDoors


-- Create the RemoteEvent
local remoteEvent = Instance.new("RemoteEvent")
remoteEvent.Name = "DoorRequestEvent"
remoteEvent.Parent = game.ReplicatedStorage
print("The Remote event was made")

timeout_number = 6

local remoteEvent = game.ReplicatedStorage:WaitForChild("DoorRequestEvent", timeout_number)

local openPosition = Vector3.new(0, 5, 0) -- Replace with the desired open position
local closedPosition = Vector3.new(0, 0, 0) -- Replace with the desired closed position

-- custom table
local openGoalTable = {} -- you could insert any goal value involving the instance you are tweening (example: you could change size, position, transparency etc just by inserting the values in this table
local closeGoalTable = {} -- same with this

openGoalTable.Position = openPosition -- adds value to table
closeGoalTable.Position = closePosition 

-- Function to handle the door movement
local function handleDoorRequest(player, doorOpen)
	local LeftBusDoor = script.Parent.BusDoors.LeftBusDoor.LeftDoor
	local RightBusDoor = script.Parent.BusDoors.RightBusDoor.RightDoor
	print("Found the Bus doors")

	
	local tweenInfo  = TweenInfo.new(1)
	
	local tweenLeftOpen = TweenService:Create(LeftBusDoor, tweenInfo, )
	local tweenRightOpen = TweenService:Create(RightBusDoor, tweenInfo, {Position = openPosition})
	
	local tweenLeftClose = TweenService:Create(LeftBusDoor, tweenInfo, openGoalTable) -- 3rd argument uses the table to set the desired goal
	local tweenRightClose = TweenService:Create(RightBusDoor, tweenInfo, closeGoalTable)
	
	-- Move the doors based on the doorOpen parameter
	if doorOpen then
		tweenLeftOpen:Play()
		tweenRightOpen:Play()
		
		textbutton.Text = "Open Bus Doors"
		print("Door Opened")
	else
		tweenLeftClose:Play()
		tweenRightClose:Play()
		
		textbutton.Text = "Close Bus Doors"
		print("Door Closed")
	end
end

-- Event listener for handling door requests
remoteEvent.OnServerEvent:Connect(handleDoorRequest)

textbutton.Activated:Connect(handleDoorRequest())

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.