The code
script.Parent.Head.ClickDetector.MouseClick:connect(function() player = game.Players.LocalPlayer.PlayerGui Sgui = Instance.new("ScreenGui", player) end)
will not work, and neither will
script.Parent.Head.ClickDetector.MouseClick:connect(function() player = game.Players.LocalPlayer.PlayerGui Sgui = Instance.new("ScreenGui") Sgui.Parent = player end)
All I want it to do is create a ScreenGui inside the player's PlayerGui. What's wrong?
I understand you wish to create a ScreenGui in someone's PlayerGui... I will try to do my best to help you.
I will assume you are running these scripts in LocalScripts. I suggest doing a few things...
1st: Use a script, and avoid LocalPlayer.
2nd: Put the script inside of the ClickDetector
3rd: Use The same function method as before but do it in this way:
script.Parent.MouseClicked:connect(function(clicked) -- Code end)
Notice how I did (clicked)
after the (function
.
Once you have completed those steps, create the ScreenGui.
script.Parent.MouseClicked:connect(function(clicked) local sgui = Instance.new("ScreenGui") end)
Now we have the ScreenGui, but its parent is nil
, therefore, we must change that. Do it by adding this line of code: sgui.Parent = clicked.PlayerGui
Once you have done that, your script should now work!
I hope I could help!
Because, head is locked? and you cant access local player from a server script. Try
function onclick(player) sgui = Instance.new("ScreenGui") sgui.Parent = player.PlayerGui script.Parent.Head.ClickDetector.MouseClicK:connect(onclick)