Why does the text button not change the value of my variable?

Hey! I’m trying to make it so that when the player clicks the red box, that when they click on a part using a raycast it will change it’s color to red. Same for other colors. (if they click on green it will switch the color to green). Like a color palet.

However I have a issue that when the text button is clicked, it doesn’t do anything.

The variable “Current Color Choice” is suppose to change but it doesn’t.


https://gyazo.com/072c3559788f443e3c572d9d9f42547d

local UserInputService = game:GetService("UserInputService")
local StarterGui = game:GetService("StarterGui")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ColorPaletGui = StarterGui.ColorPaletGui
local ColorsFrame = ColorPaletGui.Colors
local CurrentColorChoice = nil

ColorsFrame.Red.MouseButton1Down:Connect(function()
	CurrentColorChoice = Color3.fromRGB(255,0,0)
end)

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		
		local RaycastParamaterVariables = RaycastParams.new()
		RaycastParamaterVariables.FilterType = Enum.RaycastFilterType.Whitelist
		RaycastParamaterVariables.FilterDescendantsInstances = game.Workspace.Board:GetChildren()
		RaycastParamaterVariables.IgnoreWater = true
		
		local MousePosition = UserInputService:GetMouseLocation()
		
		local MouseRay = game.Workspace.Camera:ScreenPointToRay(MousePosition.X, MousePosition.Y)
		
		local Direction = MouseRay.Direction * 1000
		
		local Result = game.Workspace:Raycast(MouseRay.Origin, Direction, RaycastParamaterVariables)
		
		if Result ~= nil then
			Result.Instance.Color = CurrentColorChoice
		end
	end
end)


Have you tried printing the variable in the MouseButton1Down event to see if it’s still set as nil? If not, try doing so and see what is printed.
It’s possible that the MouseButton1Down event may not be running, either because you have probably mentioned the wrong button, or the Active property of the button(s) are disabled.