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

How to make it when you click on a player. It does something to them like kicking them?

Asked by 2 years ago

I'm trying to make it so when you click on a player's character. It does something to them, I need this for a script I'm making. Does anyone have any idea? I saw it in multiple scripts

1 answer

Log in to vote
1
Answered by
SuperPuiu 497 Moderation Voter
2 years ago

Hello! You will have to use RemoteEvent and Mouse.Target.

Now, let's begin: Add a LocalScript in StarterGui and a Script to ServerScriptService, and add as well to ReplicatedStorage a RemoteEvent and name it ClickEvent

Open the local script and begin it with:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Here we get the Mouse instance (I guess, or variable) and the Player instance.

Mouse.Button1Down:Connect(function()
      game.ReplicatedStorage.ClickEvent:FireServer(Mouse.Target)
end)

Now we fire the event with Mouse.Target parameter.

Last, open the Server script and add:

game.ReplicatedStorage.ClickEvent.OnServerEvent:Connect(function(Player, MouseTarget)
local ClickedPlr = game.Players:GetPlayerFromCharacter(MouseTarget.Parent)       
if ClickedPlr then -- You can write your function after then
              ClickedPlr:Kick("Kicked by "..Player.Name)
         end
end)

Mouse.Target

0
You explained it fantastically! Upvote :) LikeableEmmec 470 — 2y
Ad

Answer this question