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

How do I get a player that clicked a GUI?

My code looks like this:

function opengui(click, click2)
	print(click)
	print(click2)
	--local kiosk = script.Parent.Parent.Parent.Parent.Parent
	--local shopgui = kiosk:FindFirstChild("ShopGui")
	--local guiclone = shopgui:clone()
	--guiclone.Parent = click.PlayerGui
end

script.Parent.MouseButton1Down:connect(opengui)

click and click2 are both being printed out as numbers, that seem to be player position related. How do I get the player that clicked it, like I can with .Touched:connect?

1 comment

0

Try using the localplayer, Because you're the one who clicks the button anyway.

1 answer

✓ Accepted answer

Your parameters 'click' and 'click2' are being printed out as numbers because the MouseButton1Down event, the event you're using, returns two things;

  • The x coordinate that your mouse was on, on the gui.
  • The y coordinate

The event does not return the player that clicks.. so what you need to do is **make this a localscript ** and index LocalPlayer from game.Players.

local plr = game.Players.LocalPlayer --The player

function opengui(click, click2)
	local kiosk = script.Parent.Parent.Parent.Parent.Parent.ShopGui
	shopgui:Clone().Parent = plr.PlayerGui
end

script.Parent.MouseButton1Down:connect(opengui)

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