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

ClickDetector won't fire?

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?

2 answers

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!

2 comments

0

I've never heard of the clicked parameter. How did you know about it?

0

But it still doesn't work.

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)

1 comment

0

It was in a LocalScript...

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