First of all, you're missing another equal sign in your if statement.
if localplayer.click == true then
It should be like that be because when you're giving a variable a value then you use one single equal sign, but in this case, if you want to check if a variable is true then you use double equal signs ==
.
You can also use:
The click variable doesn't do anything at this point and there is a much easier way to check if the player clicked a button. MouseButton1Click does this for you, set it up like this: Gui.MouseButton1Click:connect(function()
The "Gui" you will change to the location of your gui you want to check if you clicked on.
MouseButton1Click is the method we use and :connect(function() is nothing that I can explain very well but you can read more about it here: http://wiki.roblox.com/index.php?title=Anonymous_function, basically it's a start of a function.
You can also use this methods:
local player.Script.Parent:remove()
Okey, all you did was creating a new variable that doesn't have any value. I do assume you meant to write localplayer.Script.Parent:remove()
. I do assume that this is in a local script inside the Gui and that localplayer is already defined, if not define localplayer in the beginning of the script like this:
local localplayer = game.Players.LocalPlayer
, this will only work in local scripts. The player gui should be in PlayerGui and you can access that by localplayer.PlayerGui
, but it won't be needed in this case because all we can do is script.Parent and we access the gui.
Also removing the gui is that actually what you want to do? Isn't it just much better to make it invisible by using the visible property inside gui's script.Parent.Visible = false
, if "Visible" is false then the gui becomes invisible and if I am not mistaken, non-interactive.
So the script should look something like this:
1 | local localplayer = game.Players.LocalPlayer |
3 | script.Parent.MouseButton 1 Click:connect( function () |
5 | script.Parent.Visible = false |