Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

1 comment

0

You explained it fantastically! Upvote :)

This discussion is preserved as it was. New answers, comments, and votes are closed.