Problem:
The reason you are coming up with errors is because of two major things: 1.) You need a table and 2.) You need some sort of event to pass when giving the specified player the gui you want to give. There is other problems such as location of the gui, which is not that much of a problem but it would be better to put it in replicated storage in this particular case. The reason being is because it offers more protection from exploiters and it generally helps in the long run in being able to access things in a specified place of its belonging.
Solution:
So, in your particular case you want to make a gui appear only for those that you want. Maybe friends or such. You seemed to have done this with a LocalScript, which I would highly recommend doing in a ServerScript. The reason being is because you are copying a gui from whatever place you have it, hopefully replicated storage, and putting it in the player's
PlayerGui. This is how I would set up the script generally, and note this is an example and should not be copied as it may not fit how you want it.
ServerScript
local access = {["Player1"] = true, ["Player2"] = true, ["Player3"]}
local replicated = game:GetService("ReplicatedStorage")
local gui = replicated:WaitForChild("gk"):Clone()
game.Players.PlayerAdded:connect(function(plr)
if access[plr.Name] then
print("This player can get the gui")
gui.Parent = plr:WaitForChild("PlayerGui")
else
print("This player is not in the table")
return nil
end
end)
Extra information:
Overall it seems you were trying to head in the right direction but tables are generally the easiest and most efficient way to go when it comes to these kind of things. It is basically what they are for. If you still do not understand anything don't fear to type a comment and ask. If this did help you then don't forget to upvote and accept the answer!
3 comments
o.O
'if Player.name == you or you2' is not the same as 'if Player.Name == you or Player.Name == you2'. The condition that you have written will always be satisfied because it is testing if you2 is not false or nil, which is always correct.
I also see that you're storing the GUI in Lighting. This solution is obsolete because we already have ServerStorage and ReplicatedStorage for you to store the GUI in for later use. Just remember that Local Scripts can't acquire anything from the ServerStorage.