Need help breaking down method for scripting

I made this grid and I would like help understanding how to determine which part in the grid they are. If I was to water this part (like in farming) how would I tell the game to change the color of this exact part. I’m finding it difficult to break down what needs to be done so I can script it. or do I need a click detector in every part?

Here’s one way you could implement it:

-- In a ServerScript in ServerScriptService

local function loadGridPart(gridPart)
	-- Add a click detector to the grid part so that players can click it
	local clickDetector = Instance.new("ClickDetector")
	clickDetector.Parent = gridPart
	clickDetector.MouseClick:Connect(function(playerWhoClicked)
		-- Change color example:
		print(playerWhoClicked.Name, "clicked! Changing color to red.")

		gridPart.Color = BrickColor.new("Really red").Color
	end)
end

-- Loop through all the children in the "Grid" model and call the function `loadGridPart()` on them
for _, gridPart in workspace.Grid:GetChildren() do
	loadGridPart(gridPart)
end
2 Likes

The way I would do it is when you click on your screen a workspace:GetPartBoundsInBox() is called to check the are around you, and the closest grid tile gets used and colored/watered. This method is great because there’s no excess click detectors or anything. If you use tools (Tool.Activated) it could all be done on the server too! If you want me to provide some code I’d be happy to.
If you wanted to do it on the tile you click you’d have a LocalScript check the area around the mouse or use mouse.Target and send it to the server.

Ty both for replying but I decided to use raycasting similar to the pic below so my pets can autofarm which is in the Raycasting documentation on Roblox. Now I can see what’s happening I can break down the methods.