Unable to cast to Dictionary

I’m trying to make the BackgroundColor3 of a TextButton change when a player hovers over it, but I keep getting the same “Unable to cast to Dictionary” error.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local BlackMarketGUI = ReplicatedStorage.ExploitProtectionRemoteEvents.ShowGuiEvent
local GivePlayerTool = ReplicatedStorage.ExploitProtectionRemoteEvents.GivePlayerTool
local GUI = script.Parent.Frame
local BuyDrillButton = GUI.Drill
local Drill = ReplicatedStorage.Tools.Drill
local ColorToTween = BuyDrillButton.BackgroundColor3

function ShowBlackMarket()
	local GUI = script.Parent
	GUI.Enabled = true
end

local TweenInfo = TweenInfo.new(
	0.5,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.In,
	0,
	false,
	0
)

local Goal = {
	Color3.fromRGB(90, 90, 90)
}

local Goal2 = {
	Color3.fromRGB(0, 0, 0)
}

function MouseEnter()
	local ColorTween = TweenService:Create(ColorToTween, TweenInfo, Goal)
end

function MouseLeave()
	local ColorTween = TweenService:Create(ColorToTween, TweenInfo, Goal2)
end

BlackMarketGUI.OnClientEvent:Connect(ShowBlackMarket)

BuyDrillButton.MouseButton1Click:Connect(function()
	GivePlayerTool:FireServer(Drill,750)
end)

BuyDrillButton.MouseEnter:Connect(MouseEnter)
BuyDrillButton.MouseLeave:Connect(MouseLeave)

(I really need to stop posting here lol)

1 Like

use BrickColor on both Goal dictionaries and i think using Color3 would throw error, but use BrickColor.new()

1 Like

Nothing changed I still get the same error.

1 Like

The first argument is the object and then you specify how to do it in the last place inside a table {THING YOU WANT TO CHANGE = GOAL}

TweenService:Create(BuyDrillButton, TweenInfo, {BackgroundColor3 = Goal}):Play()

1 Like
local Goal = {
	BrickColor = BrickColor.new(Color you want)
}

local Goal2 = {
	BrickColor = BrickColor.new(Color you want)
}
1 Like

TweenService:Create property named ‘BackgroundColor3’ cannot be tweened due to type mismatch (property is a ‘Color3’, but given type is ‘Array’)

“Unable to cast value to Object”

1 Like
local Goal = {
	BackgroundColor3 = Color3.FromRGB(Color you want)
}

local Goal2 = {
	BackgroundColor3 = Color3.FromRGB(Color you want)
}
``` use this instead

I still get the same error for some reason.

1 Like

After a few hours of fiddling with the code, I solved it.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local BlackMarketGUI = ReplicatedStorage.ExploitProtectionRemoteEvents.ShowGuiEvent
local GivePlayerTool = ReplicatedStorage.ExploitProtectionRemoteEvents.GivePlayerTool
local GUI = script.Parent.Frame
local BuyDrillButton = GUI.Drill
local Drill = ReplicatedStorage.Tools.Drill

function ShowBlackMarket()
	local GUI = script.Parent
	GUI.Enabled = true
end


local Goal = {BackgroundColor3 = Color3.new(0.352941, 0.352941, 0.352941)}
local Goal2 = {BackgroundColor3 = Color3.new(0, 0, 0)}

function MouseEnter()
	local ColorTween = TweenService:Create(BuyDrillButton, TweenInfo.new(0.5), Goal):Play()
end

function MouseLeave()
	local ColorTween = TweenService:Create(BuyDrillButton, TweenInfo.new(0.5), Goal2):Play()
end

BlackMarketGUI.OnClientEvent:Connect(ShowBlackMarket)

BuyDrillButton.MouseButton1Click:Connect(function()
	GivePlayerTool:FireServer(Drill,750)
end)

BuyDrillButton.MouseEnter:Connect(MouseEnter)
BuyDrillButton.MouseLeave:Connect(MouseLeave)

When creating tweens via the Create() instance method of the tween service, the keys/fields of the third argument which represents the tween’s goal must be the names of the properties being tweened, in this case the BackgroundColor3 property is being tweened of a GuiObject which is described by a Color3 value.

1 Like