Detect when player clicks on MouseClick on Client

Questions:

  • What are you trying to achieve?
    I’m trying to achieve when can you detect when player clicking a something on client.

  • Can you elaborate what are you saying?
    Alright so, when you use clients and use it for Click Detector, in Hard way, detecting click detectors in client, client is on StarterGui so the client will check every things on workspace, it it founds click detector, it will use the events and modify it

This is example of I scripted an PromixityPromptService, so I modify it so it looks good now.
I’m making a horror game. Anyways,

Is there way to modify the ClickDetector in clients? Just like how I modified the Promixity Prompt Service I wanna know it.

2 Likes

I don’t think you can modify ClickDetectors on the Client besides changing it’s Activation Distance/Mouse Icon. I think you could just stay with ProximityPromptService like how it is.

1 Like

I didnt understand, can u elaborate

1 Like

Actually, By taking a look at the ClickDetector API/Wiki You can pretty much modify it’s Activation KeyCode(s) and Callbacks with ClickDetectors/Tools by using ContextActionService:BindActivate().

1 Like

So, when I use clients for Click Detector, like how I modify the PromixityPromptService in the client so it looks better.

I was overthinking, promixity prompts in distance in which prompt will show first so maybe the prompt will be messed up.

The ClickDetector local script style is also like Prompt localscript on the video how I modified it.

So in basic terms u trying to make a Interaction system that when you hover your mouse on the object “Press E” appears?

1 Like

Yes, that’s what I’m talking about, I’m thinking if I can make Promixity Prompt and Click Detector it has same UI.

1 Like

I don’t know if I mixed PromixityPrompt and ClickDetector. Or just PromixityPrompt.

This is message what I overthink.

I did a Interaction system a long time ago that u doing now , I used this “module” that i found To See if Mouse is hovering a Part

local camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local class = {}

--[[ Parameters:
		distance (number): the distance from the camera that the method will look for a part. Leave as nil to have no set distance.
		ignore (table): the list of objects (descendants of objects in this list as well) that will be ignored.
		ignoreInvisible (boolean): if true, when there is a part with transparency of 1 in the path of the mouse's target, it will be added to the ignore list.
		ignoreCantCollide (boolean): if true, when there is a part with cancollide set to false in the path of the mouse's target, it will be added to the ignore list.
]]

class.getTarget = function(distance,ignore,ignoreInvisible,ignoreCantCollide)
	if not mouse.Hit then return end
	ignore = ignore or {}
	local function scan()
		local ray = Ray.new(camera.CoordinateFrame.p,(mouse.Hit.p - camera.CoordinateFrame.p).unit*(distance or 900))
		if ignore[1] then end --print("ignore:",ignore[1]) end
		return workspace:FindPartOnRayWithIgnoreList(ray,ignore)
	end
	local complete = false
	local hit,pos = scan()
	repeat
		if not hit or not pos then return end
		if (ignoreInvisible and hit.Transparency == 1) or (ignoreCantCollide and not hit.CanCollide) then
			table.insert(ignore,hit)
			hit,pos = scan()
		else
			complete = true
		end
	until complete
	for i,part in pairs(ignore) do
		print(part.Name)
	end
	return hit,pos
end

_G.CustomMouse = class

Altought This is A LocalScript that you need to put in StarterPlayerScripts

There’s the system I made in case you need it

InteractSystem.rbxm (10.9 KB)

1 Like

I will try that out.

char char char char char

1 Like

Okay that’s good, Thanks for the asset file. I will use this if possible.

1 Like

By the way, I am curious how you made that beam and selection box

local promixityPromptService = game:GetService('ProximityPromptService')
local tweenService = game:GetService('TweenService')
local promptGui = script.Parent:WaitForChild('Prompt')
local Beam = script:WaitForChild('Beam')

local player = game:GetService('Players').LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local attachment0 = Instance.new('Attachment')
local attachment1 = nil

attachment0.Parent = character:WaitForChild('HumanoidRootPart')

promptGui.PromptText.TextTransparency = 1
promptGui.PromptText.TextStrokeTransparency = 1

promixityPromptService.PromptShown:Connect(function(prompt, inputType)
	prompt.Style = Enum.ProximityPromptStyle.Custom
	
	tweenService:Create(promptGui.PromptText, TweenInfo.new(.1), {TextTransparency = 0}):Play()
	tweenService:Create(promptGui.PromptText, TweenInfo.new(.1), {TextStrokeTransparency = 0}):Play()
	
	script.SelectionBox.Adornee = prompt.Parent
	
	promptGui.PromptText.Text = prompt.ActionText.." ['"..prompt.KeyboardKeyCode.Name.."']"
	
	attachment1 = Instance.new('Attachment')
	attachment1.Parent = prompt.Parent
	
	Beam.Parent = workspace
	Beam.Name = 'LocalPlayerBeam'
	Beam.Attachment0 = attachment0
	Beam.Attachment1 = attachment1
end)

promixityPromptService.PromptTriggered:Connect(function()
	tweenService:Create(promptGui.PromptText, TweenInfo.new(.1), {TextColor3 = Color3.fromRGB(130, 255, 85)}):Play()
end)

promixityPromptService.PromptTriggerEnded:Connect(function()
	tweenService:Create(promptGui.PromptText, TweenInfo.new(.1), {TextColor3 = Color3.fromRGB(255, 255, 255)}):Play()
end)

promixityPromptService.PromptHidden:Connect(function(prompt)
	prompt.Style = Enum.ProximityPromptStyle.Custom

	tweenService:Create(promptGui.PromptText, TweenInfo.new(.1), {TextTransparency = 1}):Play()
	tweenService:Create(promptGui.PromptText, TweenInfo.new(.1), {TextStrokeTransparency = 1}):Play()
	
	script.SelectionBox.Adornee = script
	Beam.Attachment1 = nil
	attachment1:Destroy()
	attachment1 = nil
end)
1 Like

Really easy to achieve this, just check that the client (for which the local script is executing for) matches the player instance that clicked the ClickDetector instance.

local players = game:GetService("Players")
local localPlayer = players.LocalPlayer

local part = workspace:WaitForChild("Part")
local click = part:WaitForChild("ClickDetector")

click.MouseClick:Connect(function(player)
	if localPlayer == player then
		print("Hello world!")
	end
end)

image

I’m trying to do with scanning every instances on workspace, if the object is ClickDetector, then the event will be made. Not just like in 1 instance