Broken RemoteEvent Color Script

I want to make a remote event that whenever the mouse pressed on any part the color of it gets randomized.

the problem is that the parts brickcolor always goes to “255, 255, 255”

local replicatedstorage = game:GetService("ReplicatedStorage")
local remote = replicatedstorage.Colors
local color1 = math.random(0, 255)
local color2 = math.random(0, 255)
local color3 = math.random(0, 255)

remote.OnServerEvent:Connect(function(player, hit)
	print(color1)
	print(color2)
	print(color3)
	local mouse = player:GetMouse()
	local character = player.Character
	hit.BrickColor = BrickColor.new(color1, color2, color3)
	player.PlayerGui.ScreenGui.Frame.TextLabel.Text = ""..color1..","..color2..","..color3..""
end)

This is the script, for some reason it does not work.
Everything except this part

hit.BrickColor = BrickColor.new(color1, color2, color3)

works

I think it’s better if you randomize the color in the OnServerEvent, not outside of it

Also it’s probably giving you 255,255,255 becauwse the colors may be close to the color white. Can’t you just use hit.Color = Color3.fromRGB(color1, color2, color3) instead?

Also a few other things I noticed, trying to get the mouse from the server always returns nil, so that line can be removed. Also, I recommend giving your variables descriptive names instead of color1 to name an example, it’ll help you understand your code more clearly so you wont get any slight confusion

2 Likes