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!
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!)