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

How to open GUI when clicking a part?

Hello, I'm trying to make a script that will make a GUI in StarterGUI appear (Changing the visibility to true) when a player clicks a part in Workspace.

Here is my script:

script.Parent.Parent.Parent.Parent.ClickDetector.MouseClick:Connect(function()
	
	game.StarterGui.VehicleSelctionGUI.Frame.Visible = true
	
end)

1 answer

✓ Accepted answer

PlayerGui


When a player joins the game, all of the contents inside StarterGui are locally cloned into that player's PlayerGui, so if you want to mess around with the guis of a specific player, it would be best to run your code on a localscript, as MouseClick replicates and the first parameter of MouseClick is the player who clicked.

So, you can match the player who clicked with the localPlayer to see if the localplayer is the one who clicked the button.

--Localscript (Preferably inside VehicleSelctionGUI.Frame)
local Part = --Whatever part you are using
local Player = game.Players.LocalPlayer

Part.ClickDetector.MouseClick:Connect(function(plr)
	if plr == Player then
		script.Parent.Visible = true --if this isnt in VehicleSelctionGUI.Frame, reference it directly
	end
end)

Hopefully this helped!

2 comments

0

Thank you i'll try this out!

0

Thank you so much it works!

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