Unable to assign property color. Color3 expected, got nil

Hey everyone! I’m struggling with the color-changing system I created for my marble game, where your character is a ball. I thought it would be fairly simple, but I keep getting the error code written above when I try testing it on a multiplayer client. I have a remote function that should pass the color argument of the color buttons to the server to change the color of your ball character, but it either makes the character look black on the server or doesn’t change the color at all. Here is my server script:

Server script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CC = ReplicatedStorage:FindFirstChild("CC")

function ChangeColor(plr, color)
	print(plr)
	print(color)

	local marble = plr.Character:FindFirstChild("Marble")
	if marble then
		marble.Color = color
	return marble.Color
	end
end		

CC.OnServerInvoke = ChangeColor

Client Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CC = ReplicatedStorage:FindFirstChild("CC")


local Frame = script.Parent.Frame
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Ball = Character:WaitForChild("Marble")

for i, btns in pairs(Frame:GetChildren()) do
	if btns:IsA("ImageButton") then
		btns.MouseButton1Click:Connect(function(player, color)
			color = btns.BackgroundColor3
			CC:InvokeServer()
			Ball.Color = color
		end)
	end
end

Sorry if this is a bad way to set it up I’ve just become annoyed for how many times its failed. Any help will be appreciated, thanks

Try moving return marble.Color after the if statement and change it to return color.
Edit: wait never mind that wouldn’t work. You’re not using the return of CC.

Okay I see now. You need to include color in the parenthesis after CC:InvokeServer. It would look something like this.
CC:InvokeServer(color)

1 Like

I tried passing that argument but it would return nil to the server and only make the ball’s color black

EDIT: Nevermind, that did end up working, don’t know what happened earlier. Thanks for the help!

Maybe this will help.

ClientScript
local rs = game:GetService("ReplicatedStorage")
local cc = rs:WaitForChild("CC")
local frame = script.Parent.Frame
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local ball = char:WaitForChild("Marble")

for _, btn in pairs(frame:GetChildren()) do
	if btn:IsA("ImageButton") then
		btn.MouseButton1Click:Connect(function()
			local col = btn.BackgroundColor3
			cc:InvokeServer(col)
			ball.Color = col
		end)
	end
end

I actually posted this on the wrong thread the first time. :rofl:

1 Like

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