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)