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 make UI appear when a part is clicked?

Hello, I am currently trying to make ScreenGui appear in a Player's PlayerGui. I am having a difficult time trying to do this, someone please help!

local C1 = script.Parent.Parent.Chassis.ClickDetector


function Clicked(n)
	local character = game.Players.LocalPlayer
	local UI = game.ServerStorage.UnitUI:clone()
	local player = n:GetPlayerFromCharacter()
	UI.Parent = player.PlayerGui
end

C1.MouseClick:connect(Clicked)

UnitUI is a ScreenGui with a TextBox and other random stuff in it, which is all in ServerStorage. This is all in a LocalScript.

A response is appreciated!

1 comment

0

LocalScripts can't access the descendants of ServerStorage, hence the name 'Server Storage'

1 answer

✓ Accepted answer

As far as I know, listening to the MouseClick event of a ClickDetector should be done from a server script, because the playerWhoClicked is passed in as an argument of the RBXScriptSignal to allow the developer to know which player had clicked the ClickDetector.

Knowing this, the n in your Clicked(n) function definition is the player who clicked. Let's rename it to something more informative, such as playerWhoClicked. Remember, we want this event to be handled in a server script, so you'll have to make some simple changes that would go something like this:

local C1 = script.Parent.Parent.Chassis.ClickDetector

function Clicked(playerWhoClicked)
    local UI = game.ServerStorage.UnitUI:clone()
    UI.Parent = playerWhoClicked.PlayerGui
end

C1.MouseClick:connect(Clicked)

(another minor mistake I found is that you believed that game.Players.LocalPlayer returns a character, when in fact, it returns the actual Player object - but that is unnecessary for this script since it is a server script. Just letting you know for future reference!)

2 comments

0

Sooo you do not need the local character = game.Players.LocalPlayer line?

0

Wow, thank you!

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