i am trying to make a script that doesn't let certain people do certain things unless they are on a whitelist. It doesn't work in game and i don't really know what to do, i have tried many things.
local player = game.Players.LocalPlayer local gui = player:WaitForChild("PlayerGui").GameIntro.Start local audio = player:WaitForChild("PlayerGui").PlayerAudio gui.Play.MouseButton1Click:connect(function() if workspace.Value.Value == true then if gui.Parent.CanClick.Value == true then local id = player:GetFullName() -- gets players full username if id == "Creeper_Dude158" or "SteamSkele" then -- checks if the players full name is one of these -- not important for the issue -- end end end end)
any player can get through, not the only makes listed there. Any help and a solution? I've been searching for a while now.
the script is in a local script in starter player scripts.
The function GetFullName() returns the full ancestry string of the object you're calling it from.
What you really want is to compare two strings to see if they're similar. If so, continue with the if statement.
Since you defined the local player all you need is the Name property.
local player = game.Players.LocalPlayer local gui = player:WaitForChild("PlayerGui").GameIntro.Start local audio = player:WaitForChild("PlayerGui").PlayerAudio gui.MouseButton1Click:Connect(function() if workspace.Value.Value == true then if gui.Parent.CanClick.Value == true then local id = player.Name -- You're only looking for the name if id == "Creeper_Dude158" or id == "SteamSkele" then print(id) -- Printing out the id for testing end end end end)
Edit: did booboo, and...
Alternatively you can use a table of strings in which you can loop through to also compare if the name checks out. Usually the most common method for things like this.
local whitelist = {"Jarvis", "Craig", "Tony", "xPolarium"} local id = "xPolarium" for _, tag in pairs(whitelist) do if tag == id then print("Hello there...") end end