Trouble With Invite System

Hey there!
I’m trying to create an invite system, where you click a button that opens a scroll frame with all the players in the server listed as Text Buttons. Then when you click someone, it’s supposed to send an invite to them to join the minigame. However, the invite only shows up when you invite yourself. When you try to invite somebody else, it doesn’t show up for them. I don’t know why, so I’m just looking for someone to help me identify the issue, and guide me in the right direction to solve it.
Any and all help is appreciated!

I put the invite system into this place here, so you can take a look.

Local script #1

local debounce = false

script.Parent.MouseButton1Click:Connect(function()
	if debounce == false then
		debounce = true
		local playerToInvite = game.Players:FindFirstChild(script.Parent.Name)
		
		if playerToInvite then
			game.ReplicatedStorage.Events.InviteEvent:FireServer(game.Players.LocalPlayer, playerToInvite)
		end
		wait(3)
		debounce = false
	end
end)

Server Script

game.ReplicatedStorage.Events.InviteEvent.OnServerEvent:Connect(function(player, InvitedPlayer)
	print(player)
	print(InvitedPlayer)--To check that the event has made it this far
	wait()
	game.ReplicatedStorage.Events.InviteEvent:FireClient(InvitedPlayer, player)
end)

Local script #2

game.ReplicatedStorage.Events.InviteEvent.OnClientEvent:Connect(function(InvitedPlayer)
	script.Parent.Visible = true
	script.Parent.TextLabel.Text = InvitedPlayer.Name .. " has invited you to play a round!"
	
	local userId = InvitedPlayer.UserId
	local thumbType = Enum.ThumbnailType.HeadShot
	local thumbSize = Enum.ThumbnailSize.Size420x420
	local content, isReady = game.Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
	
	script.Parent.ImageLabel.Image = content
	script.Parent.PlayerValue.Value = InvitedPlayer.Name
end)

When you fire the server from the client, the player is already sent as the first parameter. Basically the parameters that the server received is (player, player, playerToInvite). When it got to the server, you defined the second “player” to “InvitedPlayer”. Just replace this line in script 1.

game.ReplicatedStorage.Events.InviteEvent:FireServer(game.Players.LocalPlayer, playerToInvite)

to

game.ReplicatedStorage.Events.InviteEvent:FireServer(playerToInvite)
2 Likes

I looked at the code and the place you sent. While it was a good attempt I am going to be 100% honest. I truly think you should consider rewriting the way you are doing this so called “invite system.” I am not saying this to be mean but from a professional standpoint this is not going to be very good for long term use. I find it hard to even read the code and I have been doing development for a very long time.

I hope you understand that I am not trying to grill you but rather tell you that there are better ways to do this.

Now, here is what I suggest doing.

Have a UI that has the players with a button that can be clicked to invite. Fire the server when that button is clicked with that player. Then fire the client with which is called to be prompted. Now, once you do this you can create a new remote function and check if the player returns true then we invited the player. This would be a better way than whatever you have going on here.

I hope you understand.

2 Likes

Not sure if you didn’t read his scripts or what, but what you suggested he do is exactly what he already did minus the last part in which I’m sure he hasn’t had the time to do yet. I also don’t know why you’re saying his scripts are hard to read. They really couldn’t be much better. All he could do is define some of the paths that were used multiple times.

1 Like

I wish I could say it worked, however I get this error when I click to invite someone, and it still doesn’t go through.

Could you show your current code where you made the changes? In theory this should work.

In the first local script i changed it to:

local debounce = false

script.Parent.MouseButton1Click:Connect(function()
	if debounce == false then
		debounce = true
		local playerToInvite = game.Players:FindFirstChild(script.Parent.Name)
		
		if playerToInvite then
			game.ReplicatedStorage.Events.InviteEvent:FireServer(playerToInvite)
		end
		wait(3)
		debounce = false
	end
end)

Ah, I believe that’s correct meaning your error lies here:

game.ReplicatedStorage.Events.InviteEvent:FireClient(InvitedPlayer, player)

Just so I’m understanding correctly, you’re trying to fire the client for “InvitedPlayer” and not player, correct?

Yes. I’m trying to fire the client for the player who got invited (InvitedPlayer), and show them who invited them (player).

Hm, weird that it’s not working. Would you mind putting the following in your server script and letting me know the outcome?

print(typeof(InvitedPlayer))

image
Returns as an Instance.

Why I say this is confusing is because in your test place it’s working for me after I made the changes you’ve already made. Is this your entire ServerScript? If not, do you have anything in there that would be a conflicting variable with InvitedPlayer by chance?
image_2022-03-26_073626

I don’t think so. This is my entire server script.

Typed out:

game.ReplicatedStorage.Events.InviteEvent.OnServerEvent:Connect(function(player, InvitedPlayer)
	print(player)
	print(InvitedPlayer)
	wait()
	print(typeof(InvitedPlayer))
	game.ReplicatedStorage.Events.InviteEvent:FireClient(game.Players:FindFirstChild(InvitedPlayer), player)
end)

Ah, that’s the issue, I didn’t realize that.

Change game.Players:FindFirstChild(InvitedPlayer) simply to InvitedPlayer. In your LocalScript, you’re already passing the player itself rather than a string of the players name!