Finding Another Player Through Gui Text

Basically, this is a script where you type another player name that not yours. It clones an invite and pastes it inside the playergui of the player that got invited. For some reason it does not work but when I invite my ownself the script works. There’s no errors to.

	if game.Players:findFirstChild(admin.Invite.FlagID.Text) then -- THIS IS THE PLAYER NAME THERE INVITING
			print("Found player")
			local eplayer = game.Players:FindFirstChild(admin.Invite.FlagID.Text) -- THIS IS THE PLAYER INVITED VALUE
			if eplayer:FindFirstChild("PlayerGui") then
				print("Found gui")
				local ePlayerGui = eplayer:FindFirstChild("PlayerGui") 
				
				local crewname2 = Creation.CName.Text
				local flag2 = Creation.Flag.Text
				local Captain2 = admin.CaptainText.Text
				
				local Invite = script.Invite
				local NInvite = Invite:Clone()
				NInvite.Parent = ePlayerGui
				
				NInvite.Frame.Visible = true

				NInvite.Frame.TextLabel.Text = "Crew Invite from ".. (player.Name)
1 Like

The best way to clone a gui, or any object that needs to be replicated/duplicated, is if that object is a descendant of the ReplicatedStorage. How about, you put the InviteGui (the invitation that’s being cloned into the other player) into the ReplicatedStorage.

Another problem that, I probably should’ve asked, is the type of script you’re using to clone the Gui. What type of script is this part of the code in?

1 Like

Cloning anything through a LocalScript will result in only you being able to see that cloned object.
You’ll need a RemoteEvent to get fired, to then clone the UI to the other player.

I would also recommend using string.lower() for both the search text and the player searching, so you wont have to be case sensitive when typing someones username.

2 Likes

You’ll need to use a remote event. Kinda like this.

This would be put inside of a localscript (inside of the textbox)

local TextBox = script.Parent

function Invite()
	local Player = game.Players:FindFirstChild(TextBox.Text)
	game.ReplicatedStorage.RemoteEvent:FireServer(Player)
end

TextBox.FocusLost:Connect(Invite)

This would be inside of ServerScriptService

function onInvite(Player)
	local Gui = game.ReplicatedStorage.ScreenGui:Clone()
	Gui.Parent = Player.PlayerGui
end

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(onInvite)

The LocalScript finds the player, sends the player through the RemoteEvent and the ServerScript picks it up from the Remote, allowing it to show on the other players screen! Pls lmk if you need any help

2 Likes

Yeah it was a local script that why it was not working.