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

Checking if the Player clicked another player?

Asked by 5 years ago
Edited 5 years ago

So this may seem confusing but I want to know how you find which player character a user has clicked then show a GUI using that players image, I'd think it'd be something like

local player = --Don't know
local cd = --A ClickDetector or something else

cd.MouseClick:Connect(function()
    script.Parent.Image = "https://web.roblox.com/Thumbs/Avatar.ashx?x=250&y=250&Format=Png&userid="..player.UserId
end

Any help is appreciated, thanks!

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

A little something like this should do, all i'm doing is using getting the Mouse.Target which you can learn about here after the player presses down on the left mouse button which you can learn all about the mouse here

local Player = game.Players.LocalPlayer -- Getting the player   
local Mouse = Player:GetMouse() -- Getting the players mouse]

Mouse.Button1Down:Connect(function() -- Detecting when the player presses the left mouse button

    if Mouse.Target.Parent:FindFirstChild("Humanoid") then -- Checking if the Mouse is over a player
        print(Mouse.Target.Parent.Name) -- replace this with whatever code you want 
    end

end)

and you can get the player from the character by doing

local clickedPlayer = game.Players:GetPlayerFromCharacter(Mouse.Target.Parent)
0
Yes It worked, thank you! Notrealac0unt 19 — 5y
0
No problem KinqAustinn 293 — 5y
Ad

Answer this question