PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

Color Randomizer Tool

Color Randomizer Tool

Oct 01 2018, 4:09 AM PST

The following code sample, when placed in StarterPlayerScripts will create a tool in the player’s backpack that, once equipped, will change the BasePart/BrickColor of every BasePart the player clicks on.

local Players = game:GetService("Players")

local localPlayer = Players.LocalPlayer
local backpack = localPlayer:WaitForChild("Backpack")

local tool = Instance.new("Tool")
tool.RequiresHandle = false
tool.CanBeDropped = false 
tool.Parent = backpack

tool.Equipped:Connect(function(mouse)
	mouse.Button2Down:Connect(function()
		if mouse.Target and mouse.Target.Parent then
			mouse.Target.BrickColor = BrickColor.Random()
		end
	end)
end)