Help with this Raycast

Hey! I’m trying to make it so that when I click on a certain group of parts, it will change the color of the block. I have all whitelisted parts in a folder.

My mechanism is that when I click red, it will change the CurrentColorChoice variable to the color of the textbox.

However, I’m encountering a problem in the output stating "Unable to assign property Color. Color3 expected, got nil.

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

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

local Red = ColorsFrame.Red

Red.Activated:Connect(function(input)
	print("Red is your current color")
	CurrentColorChoice = Color3.new(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.Instance then
			Result.Instance.Color = CurrentColorChoice
		end
	end
end)

Are the ColorsFrame.Red a Button?

you have to add if gameProcessedEvent then return end inside the InputBegan function

set this variable to something default and don’t set it as nil

local CurrentColorChoice = Color3.new(255, 0, 0)

or in this if statement, check if the color selected is not nil

if input.UserInputType == Enum.UserInputType.MouseButton1 and CurrentColorChoice then

i did that, but the text button doesn’t change the color at all. the default color just stays the same

however when i add scripts in the text buttons it works, do you know how i can communicate two local scripts with each other?

ohhh, i had to use a bindable function to communicate the two client scripts

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.