Hello, I am trying to make a local script that (let's say that "Player1" and "Player2" joins) gives Player1 and Player2 specific GUI and not Player3. I found something like this on the internet, but it was a script to only give the gui to you. I tried to modify it, but it turns out that it will give everyone the Gui in game, so the script that I tried to make changes to doesn't work. Here is the local script:
while true do if game.Players.LocalPlayer.Name == "Player1" or "Player2" then wait() else script.Parent:Destroy() end end
Doing this makes all players get the gui, and I don't want that to happen. How would I make it so that only (lets say) Player1 and Player2 get the gui? Sorry if it is really simple because I don't really know how to write scripts.
Hello. First of all you don't need to run a while true do
loop to detect the name. This can be done by running the script a single time. Second, instead of deleting the script, you can have it run once and then stop. This setup requires you to put your ScreenGui
in ReplicatedStorage
local Player = game.Players.LocalPlayer--Here, we define the player. if Player.Name == "Player1" or "Player2" then--If player is equal to x or y then local Gui = game.ReplicatedStorage.ScreenGui:Clone()--Defines what ScreenGui to copy Gui.Parent = Player.PlayerGui--Sets copied ScreenGui into PlayerGui end
If you found this helpful, please accept the answer.