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
COMMUNITY QUESTION
How to make it when you click on a player. It does something to them like kicking them?
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
You explained it fantastically! Upvote :)