So basically i'm making a minigame game and i'm making a textbutton only visible to the usernames I put so they can tp to the host box and have easy access to every minigame without needing to fly miles away.
Here is the current script:
local Gui = game.ReplicatedStorage.HostOnlyGui local Hosts = game.Players:WaitForChild("Nitrolux200") wait() Gui.Parent = Hosts.PlayerGui
I tried adding more usernames in "local Hosts" section but it didn't seem to work with multiple, it only works with 1. Can anyone help me know how to make it so I can place in many usernames instead of just 1 [mine] ?
You're looking to take advantage of Tables, here specifically, the Dictionary variant. You can use this to store the UserIds
(a static and unique identifier) of the Players you wish to authorize the usage of this UI within it, opening an efficient way of properly handling the distribution of your GUI.
ReplicatedStorage
is a shared space between the Client and Server. Giving an Instance with the magnitude of "host permissions" this home wouldn't be wise. Store it under the Script
disbursing it—which should be located under ServerScriptService
.--###----------[[SERVICES]]----------###-- local Players = game:GetService("Players") --###----------[[VARIABLES]]----------###-- local AuthorizedUsers = { [--[[USERID (MANDATORY)]]] = --// Username } local GUI = script.HostOnlyGui --###----------[[INITIALIZATION]]----------###-- Players.PlayerAdded:Connect(function(Player) if (AuthorizedUsers[Player.UserId]) then --------------- GUI:Clone().Parent = Player.PlayerGui end end)
You need to use tables.
local Gui = game.ReplicatedStorage.HostOnlyGui local Hosts = {"Nitrolux200","SomeoneElse"} wait() for i,v in pairs(Hosts) do local Player = game.Players:WaitForChild(v) local newGui = Gui:Clone() newGui.Parent = Player.PlayerGui end
Hope this helps!