✓ Accepted answer
That is because the server does not know which player and character its supposed to use. In other words, you can't use game.Players.LocalPlayer in server scripts.
There are many possible solutions to this problem. The one I will provide is not very efficient, but should solve your problem. If you have many bricks like this, copying this script over and over may introduce significant lag.
So lets assume the brick will change colour with the nearest character head colour and that it will update nearest character every second. You may of course update more often, but beware of the aforementioned lag.
local brick = script.Parent
while true do
local shortestMagnitude = 100000
local nearestHead = nil
for _, player in pairs(game.Players:GetPlayers()) do
if player.Character then
local head = player.Character:FindFirstChild("Head")
if head then
if (head.Position - brick.Position).Magnitude < shortestMagnitude then
shortestMagnitude = (head.Position - brick.Position).Magnitude
nearestHead = head
end
end
end
end
if nearestHead then
brick.Color = nearestHead.Color
end
wait(1)
end
Please read about Touched event, as it may be better solution for this problem.