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)
local Goal = {
BackgroundColor3 = Color3.FromRGB(Color you want)
}
local Goal2 = {
BackgroundColor3 = Color3.FromRGB(Color you want)
}
``` use this instead
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.