Color doesn't change when pressed button

This is the local script and it has an error in it:

game.ReplicatedStorage.FixesFolder.GamepassTools.MakeRed.OnServerEvent:Connect(function(Player, Tool, Handle) 
    Handle.BrickColor = BrickColor.new("Really red")
end)

well, what’s the error? I can’t really help without it.

attempt to use index nil with ‘Color’

Ok, I know why. This is because you’re passing the full object. This error doesn’t happen to me but i’ll make it so it doesn’t pass the full object. Just give me a few minutes to write the new script.

ok, heres the new LOCAL SCRIPT:

script.Parent.MouseButton1Click:Connect(function()
	local Player = game.Players.LocalPlayer
	local Character = Player.Character
	local Backpack = Player.Backpack
	local BackPackTool = Backpack:FindFirstChild("LightStick")
	local CharTool = Character:FindFirstChild("LightStick")
	if BackPackTool then -- if the tool is NOT equipped. Aka in the player's backpack
		BackPackHandle = BackPackTool:FindFirstChild("Handle") -- this is a global variable. If it has an orange line underneath it then don't worry.
	end
	if CharTool then --- if the tool IS equipped. Aka in the player's character.
		CharHandle = CharTool:FindFirstChild("Handle") -- this is a global variable. If it has an orange line underneath it then don't worry.
		end
	if BackPackTool then
		game.ReplicatedStorage.FixesFolder["MikeGFX's_Folder"].MakeRed:FireServer(BackPackTool, BackPackHandle.Name, Backpack, Character) -- this is what will be sent to the server.
	elseif CharTool then -- if the tool isn't in the back pack then this will happen.
		game.ReplicatedStorage.FixesFolder["MikeGFX's_Folder"].MakeRed:FireServer(CharTool.Name, CharHandle)
		end
end)

Here is the new SERVER SCRIPT:

game.ReplicatedStorage.FixesFolder["MikeGFX's_Folder"].MakeRed.OnServerEvent:Connect(function(Player, ToolName, Handle, NilBackPack, nilCharacter) -- PLAYER IS AUTOMATICLY THERE! DON'T REMOVE PLAYER!
	-- if anything has nil infront of it DON'T use it! 
	local BackPack = Player.Backpack
	local Character = Player.Character
	local FindToolInBackPack = BackPack:FindFirstChild(ToolName)
	if FindToolInBackPack then
		local ToolHandle = FindToolInBackPack.Handle
		ToolHandle.BrickColor = BrickColor.new("Really red")
	elseif Character:FindFirstChild(ToolName) then
		local CharTool = Character:FindFirstChild(ToolName)
		local CharToolHandle = CharTool.Handle
		CharToolHandle.BrickColor = BrickColor.new("Really red")
	
	end
end)

this is how the script works btw: https://gyazo.com/88faa9b7ed3f4ce375aadfaec31b15c4

Actually I did a wrong thing in the server script. oopsie heres the new one:

script.Parent.MouseButton1Click:Connect(function()
	local Player = game.Players.LocalPlayer
	local Character = Player.Character
	local Backpack = Player.Backpack
	local BackPackTool = Backpack:FindFirstChild("LightStick")
	local CharTool = Character:FindFirstChild("LightStick")
	if BackPackTool then -- if the tool is NOT equipped. Aka in the player's backpack
		BackPackHandle = BackPackTool:FindFirstChild("Handle") -- this is a global variable. If it has an orange line underneath it then don't worry.
	end
	if CharTool then --- if the tool IS equipped. Aka in the player's character.
		CharHandle = CharTool:FindFirstChild("Handle") -- this is a global variable. If it has an orange line underneath it then don't worry.
		end
	if BackPackTool then
		game.ReplicatedStorage.FixesFolder["MikeGFX's_Folder"].MakeRed:FireServer(BackPackTool.Name, BackPackHandle, Backpack, Character) -- this is what will be sent to the server.
	elseif CharTool then -- if the tool isn't in the back pack then this will happen.
		game.ReplicatedStorage.FixesFolder["MikeGFX's_Folder"].MakeRed:FireServer(CharTool.Name, CharHandle)
		end
end)

Tool.Color = Color3.new(255, 0, 0)

change that to Tool.Color = Color3.fromRGB(255, 0, 0)
try that

local repStorage = game:GetService("ReplicatedStorage")
local makeRed = repStorage:WaitForChild("FixesFolder"):WaitForChild("GamepassTools"):WaitForChild("MakeRed")

script.Parent.MouseButton1Click:Connect(function()
	makeRed:FireServer()
end)
local repStorage = game:GetService("ReplicatedStorage")
local makeRed = repStorage:WaitForChild("FixesFolder"):WaitForChild("GamepassTools"):WaitForChild("MakeRed")

makeRed.OnServerEvent:Connect(function(player)
	local backpack = player:WaitForChild("Backpack")
	local lightStick = backpack:WaitForChild("LightStick"):WaitForChild("Handle")
	lightStick.Color = Color3.new(1, 0, 0)
end)

First of all, you can’t define the player instance using “game.Players.LocalPlayer” inside a server script, second of all when you call the FireServer() function, the player instance pertaining to the client of which fired the server is automatically passed as an argument to any function connected to the corresponding “OnServerEvent” event handler, meaning that we can simply declare a parameter of this connected function named “player” or something which resembles the player in order to handle this passed player instance. Thirdly, Color3.new() only accepts components of which are number values between 0 and 1 exclusively, if you want to convert RGB to Color3 simply divide the components by 255, like I have done in the above script.

Personally I don’t Color3.new(), I use Color3.fromRGB()
You tried the colour red I see, try this.

game.ReplicatedStorage.MakeRed.OnServerEvent:Connect(function()
	local Player = game.Players.LocalPlayer
	local Backpack = Player.Backpack
	local Tool = Backpack:WaitForChild("LightStick"):WaitForChild("Handle")

	Tool.Color = Color3.fromRGB(255, 0, 0)
end)

This has already been provided, check the post above mine.

People like to have examples, it’s always good to have a example other than explaining it.

I essentially provided it too, albeit slightly differently.

1 Like
game.ReplicatedStorage.MakeRed.OnServerEvent:Connect(function()
    local Player = game.Players.LocalPlayer
    local Backpack = Player.Backpack
    local Tool = Backpack:WaitForChild("LightStick"):WaitForChild("Handle")

Tool.Color = Color3.FromRGB(255, 0, 0)
end)

That only works if the tool is in the player’s back pack. When the tool is equipped it goes to the character. Look at my 2nd to last post before this and you’ll see what I mean.