Is there a way to detect mouse click?

Hello developers, Im trying to make a system that checks the values of a model when it has been clicked. But im unsure of how the local script would detect it. Since there are multiple models, i would like it so it detects whenever a clickdetector throughout the whole game has been activated it runs a function kind of like game:GetService(“ProximityPromptService”).PromptTriggered but with clickdetectors.

I would reccomend using a raycast system to fire a raycast when the user clicks their mouse or taps the screen.

This may be useful:
Raycast Documentation

Here is an example of what a local script using this may look like:

local Mouse = game.Players.LocalPlayer:GetMouse()
Mouse.Button1Up:Connect(function()
	
	local Parameters = RaycastParams.new()
	-- Customise the raycast parameters (I would recommend excluding the character)
	
	local Distance = 100 -- Distance of the ray
	
	local Cast = Mouse.UnitRay
	local Raycast = game.Workspace:Raycast(Cast.Origin, Cast.Direction*Distance, Parameters)

	if Raycast then
		if Raycast.Instance then -- Checks for the part or terrain the raycast hit 	
			-- Add some code to get the model from the part it hits
			-- Code to show the values here
		end
	end
	
end)

Hope this helps :slight_smile:

2 Likes

Appreciate the help! thanks alot

2 Likes

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