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.
COMMUNITY QUESTION
How to make a script that gives you money if you click someone of the criminals team?
1 answer
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
how could I add that police can only arrest criminals?
You'd need to script that by checking for Player.Team.