Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to make a script that gives you money if you click someone of the criminals team?

Asked by
Tripyfy 28
6 years ago

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.

1 answer

Log in to vote
0
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago

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.

0
how could I add that police can only arrest criminals? Tripyfy 28 — 6y
0
You'd need to script that by checking for Player.Team. Avigant 2374 — 6y
Ad

Answer this question