Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I get a Gui to show up for another player?

I'm relatively new to scripting, so I'm sorry if some of these questions suck, haha. I've really enjoyed learning as much as I have so far. Anyway, as the title states, I'm working on a party Gui that you'd find in any mmo or regular rpg. However, I'm having a bit of trouble, and all the help I could get would be really appreciated!

Here's a bit of the script that I whipped up:

print("partyGui loaded")

main = script.Parent
player = main.Parent.Parent.Parent
character = player.Character

local players = game.Players:GetChildren()

invOptions = main.invOptions

plr1 = player
plr2 = main.partyActive.plr2
plr3 = main.partyActive.plr3
plr4 = main.partyActive.plr4

inviteMenu = main.partyActive.invite

invGui = main.invPlayer
invButton = invGui.invite
cancelbutton = invGui.cancel

invButton.MouseButton1Click:connect(function()
	if plr2.Visible == false and invGui.playerName.Text ~= "Type name here" then
		local a = tostring(invGui.playerName.Text)
		invClone = invOptions:Clone()
		invClone.Parent = players.a
		invClone.Visible = true
		invGui.invInfo.Text = "Player has been invited!"
		wait(1)
		invGui.invInfo.Text = ("Sending invitation to " ..a)
		wait(1)
		invGui.Visible = false
		plr2.Visible = true
		plr2.Text = (""..a)
	else
		invGui.invInfo.Text = "Player does not exist!"
		wait(2)
		invGui.invInfo.Text = "Type the player's name below!"
	end
end)

inviteMenu.MouseButton1Click:connect(function()
	if invGui.Visible == true then
		print("Already open!")
	elseif invGui.Visible == false then
		wait(.25)
		invGui.Visible = true
		print("Opening menu!")
	end
end)

https://gyazo.com/60738890927fbdf5f0c5ffcc0ac78d30 (Controller is the name of the script)

So, what I need help with are firstly, getting invClone to be copied and made visible for the person that was invited, so that they can accept or decline the invitation to join someone's party. As you can see, I tried to make invClone.Parent equal to the text of invGui.playerName, which is a text box (the idea is that you type the player's name there, then hit the invite button). However, this doesn't seem to work, and I have absolutely no idea how to fix it. There are no errors in output or anything.

Secondly, is there some way that I can have the script check to see if the person being invited is an actual player in the server? Right now, I have it so that if the text of the playerName text box is at it's default ("Type name here"), the text label invInfo will change to "Player does not exist!". What I need is to get that to occur every time someone tries to invite a player that actually doesn't exist, whether the player isn't in that server, or they misspelled their username.

https://gyazo.com/12acc278cd60f9bec44312bab50c10dc https://gyazo.com/12acc278cd60f9bec44312bab50c10dc (what plr2 looks like, not sure if that'll help any.)

Thirdly, I'm going to need to get the party to update for both people (meaning the person who joins the party will have the gui show up and all that, but the person who invited them will be 'player two', I guess?), and I need that to be dependent on whether the person who was invited accepted the invitation, or declined it. Any ideas on how I can make that happen?

Hopefully that all made sense! Thanks in advance!

1 answer

✓ Accepted answer
  1. To display a GUI to a player, you put in the PlayerGui of the player. For example, you might do something like this:
gui:Clone().Parent = game.Players.Monsieur_Robert.PlayerGui -- Moves a clone of the GUI into Monsieur_Robert's player gui. This GUI will be displayed on their screen.
  1. Player objects are stored in the players service. Because of this, we can use the FindFirstChild to get a player by their name, and more importantly, check if they exist. We can take advantage of this by doing:
if game.Players:FindFirstChild("Monsieur_Robert") then -- If nil (player is not in players), this if statement will return false.
	print("Player Monsieur_Robert exists.")
end
  1. I am not sure exactly what you mean, but try adding something to your click event to make the gui show up for the player only if they accepted the invitation, using #1.

5 comments

0

I need the second Gui to be made visible for player2 if player1 presses their Gui. As in, if I (player1) press the button called "Invite," then player2 should see a Gui that prompts them to accept or decline my invitation. I also tried to use FindFirstChild, but I need it to look for whatever was typed into playerName, which is kind of unknowable, right? I mean, in this project, I don't want only

0

-- "Monsieur_Robert" to be what the script looks for in Players. Rather, it should look for whatever was typed into the textbox "playerName." Sorry, it cut me off. Hopefully that helps, and thanks for the advice!

0

You get the player name that the player put in by using the Text property of your text box. For example, if someone wants to invite builderman you can figure that out by using textbox.Text

0

So for example, game.Players:FindFirstChild(invgui.playerName.Text)

0

I see why that didn't work in my original attempt at using FindFirstChild. I wrote something like "if game.Players:FindFirstChild(invGui.playerName.Text) ~= nil then" or something. Seems to work as just "if game.Players:FindFirstChild(invGui.playerName.Text) then" though, so thank you very much!

This discussion is preserved as it was. New answers, comments, and votes are closed.