Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

ClickDetector won't fire?

Asked by
emite1000 335 Moderation Voter
9 years ago

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

Log in to vote
1
Answered by 9 years ago

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!

0
I've never heard of the clicked parameter. How did you know about it? emite1000 335 — 9y
0
But it still doesn't work. emite1000 335 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

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)
0
It was in a LocalScript... emite1000 335 — 9y

Answer this question