I'm developing a game and I need a script that goes inside a tool and if you click someone from the criminal team with it you receive 10k money for example.
You can use the UserInputService.InputBegan
event to collect user input, and process it like so:
local Services = { UserInput = game:GetService("UserInputService") } local function OnUserInputBegan(InputObject, GameProcessedEvent) if GameProcessedEvent then return end if InputObject.UserInputType ~= Enum.UserInputType.MouseButton1 then return end -- Code here! end Services.UserInput.InputBegan:Connect(OnUserInputBegan)
Next, you'd want to get the player that the user is clicking on. You can accomplish this by using the old and outdated PlayerMouse
API via Player:GetMouse()
, and accessing PlayerMouse.Target
, or, alternatively, casting a ray from the Camera's 3D point in the direction of the mouse (you can access positional mouse information via InputObject
in our example.