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

FInding the player for MouseButton1Click?

Hey, guys. I'm trying to make a gui appear on the screen when you click on a part. I've already achieved doing this using a Click Detector inside the part, but I was wondering how you would accomplish this using Suface Gui. This is what I tried doing so far:

script.Parent.MouseButton1Click:connect(function(Player)
	local part = script.Parent.Parent.Parent
	local gui = part:FindFirstChild("ScreenGui")
	part.BrickColor = BrickColor.new("Really red")
	if gui then
		local newgui = gui:Clone()
		newgui.Parent = Player.PlayerGui
	end
	wait(1)
	part.BrickColor = BrickColor.new("Dark stone grey")
end)

As you can see, the color of the brick changes red as expected (line 4), but the gui doesn't clone (line 7). I'm having trouble figuring out how I would locate the player that clicked the part, and I would gladly appreciate anyone how could help me solve this problem.

1 comment

0

MouseButton1Click does not return player.

1 answer

MouseButton1Click does not return "Player". The best way to do this is to make this into a LocalScript defining player as LocalPlayer, you will then have to set the Adornee of the SurfaceGui to the part in workspace you would like it to appear on.

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