Error Unable to cast value to Object

I’m trying to make a randomize color game, where randomized color plates will be generated and all of them will be destroyed and one will remain. So i want the frame to change to the remaining color. But it gave me an error "Unable to cast value to Object "

server script

local Plates = game.Workspace.Plates.Model:GetChildren()
local RemainingColorA = game.ReplicatedStorage:WaitForChild("RemainingColor")

local RandomColors = {
	BrickColor.new("White"),
	BrickColor.new("Really black"),
	BrickColor.new("Really red"),
	BrickColor.new("Really blue"),
	BrickColor.new("New Yeller"),
	BrickColor.new("Cyan"),
	BrickColor.new("Magenta"),
	BrickColor.new("Pink"),
	BrickColor.new("Deep orange"),
	BrickColor.new("Brown"),

}

local waitTime = 7
local waitBetween = 3



while task.wait() do
for _, v in Plates do
	local randomIndex = math.random(1, #RandomColors)
	local randomColor = RandomColors[randomIndex]
	v.Transparency = 0
	v.CanCollide = true
	v.BrickColor = randomColor
end

local randomIndex2 = math.random(1, #RandomColors)
local remainingColor = RandomColors[randomIndex2]
RemainingColorA:FireClient(remainingColor)

print(remainingColor)

task.wait(waitTime)

for _, v in Plates do
	if v.BrickColor ~= remainingColor then
		v.Transparency = 1
		v.CanCollide = false
	end
end

task.wait(waitBetween)
waitTime = waitTime - 0.4
waitBetween = waitBetween - 0.02


end

local script

local Frame = game.StarterGui.Color.Frame.Frame
local Text = game.StarterGui.Color.Frame.TextLabel
local RemainingColorA = game.ReplicatedStorage:WaitForChild("RemainingColor")

RemainingColorA.OnClientEvent:Connect(function(a)
	Frame = a
	Text = tostring(a)
end)
2 Likes

It would be Text.Text as you want to set the text property of it not the actual object of it

1 Like

i wanted to change the color of the frame

1 Like

Then make it be Frame.Color = a as that would set the color property of it

1 Like

i’m sorry i think i haven’t explained the problem enough.

so i wanted to share “remainingColor” which is a brickcolor to the local script with the remote event, but it don’t work and i got an error “Unable to cast value to Object” how do i solve this?

3 Likes

Currently you are trying to set the Frame Object as a brick color and the Text object as a brick color which isn’t allowed

1 Like

In here you need to define which client to fire. remainingColor is not a player

RemainingColorA:FireClent(player, remainingColor)

Also in your LocalScript:

I believe it should be this:

local localPlayerGui = game.Players.LocalPlayer.PlayerGui

local Frame = localPlayerGui.Color.Frame.Frame:: Frame
local Text = localPlayerGui.Color.Frame.TextLabel:: TextLabel
local RemainingColorA = game.ReplicatedStorage:WaitForChild("RemainingColor")

RemainingColorA.OnClientEvent:Connect(function(a: BrickColor)
	Frame.BackgroundColor = a
	Text.Text = tostring(a)
end)
4 Likes