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

Checking if the Player clicked another player?

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

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)

2 comments

0

Yes It worked, thank you!

0

No problem

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