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

How to detect a click on another player?

Asked by 3 years ago

How would one go about detecting when one player clicks another player? For example if I wanted the person being clicked to die and sent back to the lobby spawn.

2 answers

Log in to vote
1
Answered by
rkdss 25
3 years ago

You need 2 scripts in startercharacterscripts and 1 remote event in replicated storage with name "clickevent" First local script:

local mouse = game.players.localplayer:GetMouse()
mouse.Button1Down:Connect(Function()
game.ReplicatedStorage.clickevent:FireServer(mouse.Target)
end

Second server (global) script:

game.ReplicatedStorage.clickevent.onServerEvent:Connect(function(player, target)
--Script Here
end

target = mouse target (Model or Part Value) player = player who clicked (Player Value)

Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

This is what you would want to do. I never tried it but ITS OK I TRY MY HARDEST. First make a rig with rig creator second name it "StarterCharacter" then put it in game.StarterPlayer. BUT DONT DO STEP 3 YET Step 2A: Make a click detector inside the UpperTorso (or torso in r6). THEN do step 3. This is the tricky part but i can manage. THE CODE!

function onClicked()
local Player = script.Parent.Parent
Player.Humanoid.Health = 0
script.Parent.ClickDetector.MouseClick:connect(onClicked)

also PLUS, I dont know how to make it your own character. KIDDING! Just use th- ok nevermind. it might get to confusing for now. Your welcome fellow scripter!

0
oh yeah this is my edit. PUT THE SCRIPT INSIDE UPPERTORSO! (or torso for r6) snowpototoy 37 — 3y
0
Use :Connect() instead of :connect() as it is deprecated! RazzyPlayz 497 — 3y

Answer this question