Is there a way to get the color of a single pixel on your screen using scripts?

I was wondering if you could make something like “pick screen color” on Roblox. Does anyone have any idea if this is possible?

5 Likes

Do you mean like the color of a single pixel on your screen?

script.Parent.Color = Color3.new(1,0,0) or Color3.fromRGB(255,0,0)-- Color is red (Part)

Or:

script.Parent.BackgroundColor3 = Color3.new(1,0,0) or Color3.fromRGB(255,0,0) -- Color is red (GUI)
1 Like

Yes, sorry I made that unclear.

1 Like

There’s no way to get the screen’s pixel data, I believe. Would honestly be cool if they added it.

1 Like

That’s completely different to what they’re asking…

2 Likes

You edit does not work either. They are looking for a method to get pixel color of a user’s screen, not setting the color of the UI or setting a part’s color.

A color picker if you will.

1 Like

I believe There is most likely no non-hacky way to get the screen’s pixels directly, however the closest thing you can get to it is convert vector2 of the pixel to world data using ScreenPointToRay and the closest part to it and get its color, however this doesn’t account for UIs, textures and meshes.

2 Likes

Here’s an idea I have in my head.

Get the Vector2 value of a pixel that you want, raycast towards it with ScreenPointToRay(), then get the color of the part that it’s touching.

6 Likes

Not to mention, this won’t also certainly account for screen-space effects (bloom, blur, etc), shadows, lights, skybox, and to some extent the curvature of meshes (I believe it’s possible to use rays?)

2 Likes

This may certainly be the only way to get “pixel” data. Approximating to account for many effects is probably ray-tracing, which is going overboard lol.

2 Likes

I guess that is the closest way to achieve this. I hope Roblox will add a feature to get the color of UIs and decals in the future. Thanks to everyone else who have helped me with this topic!

@Y_VRN
@CipherFunctions

Look at the video (Sorry for mentions).

The script:

script.Parent.Color = Color3.new(1,0,0) or Color3.fromRGB(255,0,0)
2 Likes

The topic says “get the color of a single pixel on your screen”, not “set color of a part.”

I’m not going to reply here anymore as this topic already have a solution.

2 Likes

Mouse.Hit returns the part the mouse is hovering over, so you can skip the process of raycasting and just get the active part like this.

2 Likes

Yes that’s true (if he wants the mouse’s position). Otherwise, he can use raycasting.

local Game = game
local UserInputService = Game:GetService("UserInputService")
local Players = Game:GetService("Players")
local Player = Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")

local function OnInputBegan(InputObject, GameProcessed)
	if GameProcessed then return end
	if InputObject.UserInputType.Name ~= "MouseMovement" then return end
	local GuiObjects = PlayerGui:GetGuiObjectsAtPosition(InputObject.Position.X, InputObject.Position.Y - 36) --Account for gui inset.
	for _, GuiObject in ipairs(GuiObjects) do
		print(GuiObject.BackgroundColor3)
	end
end

UserInputService.InputBegan:Connect(OnInputBegan)

This obviously won’t work for gui objects which cast an image like ‘ImageLabels’ or ‘ImageButtons’.

3 Likes