Local script running for the wrong client

I am attempting to create a lobby system. I have all of the game settings and other features working, I just can’t seem to get the joining function down. My problem is when you click join on the lobby, it is supposed to create a ui frame in the owner’s lobby creation Ui, but it creates it for the one who joined. When you click join, it shows the creation Ui, but only for testing.

This is the script that is supposed to fire the event so the Ui is created. The other code changes image id’s on the lobby ui to show the current joined players.

JoinCount = 0
script.Parent.MouseButton1Click:Connect(function()
	local Owner = script.Parent.Parent.HostPlayer.HostPlayerName.Value
	if script.Parent.Text == "Lobby Is Full" then
	else
		if JoinCount <= 3 then
			if JoinCount == 0 then
				local Players = game:GetService("Players")
				local Player = game.Players.LocalPlayer
				local player = game.Players:FindFirstChild(Player.Name)
				local ThumbnailType = Enum.ThumbnailType.HeadShot
				local ThumbnailSize = Enum.ThumbnailSize.Size180x180
				script.Parent.Parent.GeustPlayer1.Image = Players:GetUserThumbnailAsync(Player.UserId, ThumbnailType, ThumbnailSize)
				local StringValue = Instance.new("StringValue")
				StringValue.Name = "GeustPlayer1Name"
				StringValue.Parent = script.Parent.Parent.GeustPlayer1
				StringValue.Value = Player.Name
				game.ReplicatedStorage.JoinPlayer:Fire(Owner, JoinCount, player)
				JoinCount += 1
			elseif JoinCount == 1 then
				local Players = game:GetService("Players")
				local Player = game.Players.LocalPlayer
				local player = game.Players:FindFirstChild(Player.Name)
				local ThumbnailType = Enum.ThumbnailType.HeadShot
				local ThumbnailSize = Enum.ThumbnailSize.Size180x180
				script.Parent.Parent.GeustPlayer2.Image = Players:GetUserThumbnailAsync(Player.UserId, ThumbnailType, ThumbnailSize)
				local StringValue = Instance.new("StringValue")
				StringValue.Name = "GeustPlayer2Name"
				StringValue.Parent = script.Parent.Parent.GeustPlayer1
				StringValue.Value = Player.Name
				game.ReplicatedStorage.JoinPlayer:Fire(Owner, JoinCount, player)
				JoinCount += 1
			elseif JoinCount == 2 then
				local Players = game:GetService("Players")
				local Player = game.Players.LocalPlayer
				local player = game.Players:FindFirstChild(Player.Name)
				local ThumbnailType = Enum.ThumbnailType.HeadShot
				local ThumbnailSize = Enum.ThumbnailSize.Size180x180
				script.Parent.Parent.GeustPlayer3.Image = Players:GetUserThumbnailAsync(Player.UserId, ThumbnailType, ThumbnailSize)
				local StringValue = Instance.new("StringValue")
				StringValue.Name = "GeustPlayer3Name"
				StringValue.Parent = script.Parent.Parent.GeustPlayer1
				StringValue.Value = Player.Name
				game.ReplicatedStorage.JoinPlayer:Fire(Owner, JoinCount, player)
				JoinCount += 1
				script.Parent.Text = "Full"
			end
		end
	end
end)

This is the script that is receiving the remote event, and SHOULD create the joined player Ui for the Host, it doesn’t :frowning:

game.ReplicatedStorage.JoinPlayer.Event:Connect(function(Owner, JoinCount, player) 
	print(script.Parent.HostPlayer.Player.Value)
	--if Owner == script.Parent.HostPlayer.Player.Value then
	if JoinCount == 0 then
		script.Parent.Parent.Parent.LobbyCreationUi.Visible = true
		script.Parent.Parent.Parent.LobbyListUi.Visible = false
		print(player.Name.." Has Joined The Lobby")
		print(game.Players.LocalPlayer.Name)
		local GeustPlayer1 = game.Lighting.GeustPlayer1:Clone()
		GeustPlayer1.Parent = script.Parent
		local Players = game:GetService("Players")
		local ThumbnailType = Enum.ThumbnailType.HeadShot
		local ThumbnailSize = Enum.ThumbnailSize.Size180x180
		GeustPlayer1.ImageLabel.Image = Players:GetUserThumbnailAsync(player.UserId, ThumbnailType, ThumbnailSize)
		local StringValue = Instance.new("StringValue")
		StringValue.Name = "GeustPlayer1Name"
		StringValue.Parent = GeustPlayer1
		StringValue.Value = player.Name
	elseif JoinCount == 1 then
		print(player.Name.." Has Joined The Lobby")
		local GeustPlayer2 = game.Lighting.GeustPlayer2:Clone()
		GeustPlayer2.Parent = script.Parent
		local Players = game:GetService("Players")
		local ThumbnailType = Enum.ThumbnailType.HeadShot
		local ThumbnailSize = Enum.ThumbnailSize.Size180x180
		GeustPlayer2.ImageLabel.Image = Players:GetUserThumbnailAsync(player.UserId, ThumbnailType, ThumbnailSize)
		local StringValue = Instance.new("StringValue")
		StringValue.Name = "GeustPlayer1Name"
		StringValue.Parent = GeustPlayer2
		StringValue.Value = player.Name
	elseif JoinCount == 2 then
		print(player.Name.." Has Joined The Lobby")
		local GeustPlayer3 = game.Lighting.GeustPlayer3:Clone()
		GeustPlayer3.Parent = script.Parent
		local Players = game:GetService("Players")
		local ThumbnailType = Enum.ThumbnailType.HeadShot
		local ThumbnailSize = Enum.ThumbnailSize.Size180x180
		GeustPlayer3.ImageLabel.Image = Players:GetUserThumbnailAsync(player.UserId, ThumbnailType, ThumbnailSize)
		local StringValue = Instance.new("StringValue")
		StringValue.Name = "GeustPlayer1Name"
		StringValue.Parent = GeustPlayer3
		StringValue.Value = player.Name
	end
	--end
end)

I have searched on the forum posts, it seems nobody else has this same problem.

1 Like

This hurts my eyes
kskslalwpqpqppq

2 Likes

So a couple things immediately jump out.
First, the first parameter for the event handler is always the player who fired the remote event.
So for an event that is fired from a local script like:

game.ReplicatedStorage.JoinPlayer:Fire(param1, param2)

Then on ther server you would need to connect it like

game.ReplicatedStorage.JoinPlayer.Event:Connect(function(Player, param1, param2)
...
end)

Also in general for a lobby type functionality what I’ve found to be a simpler way to handle it is with Folders in ReplicatedStorage that GUI’s can listen to.

So you could have a “Lobbies” folder in ReplicatedStorage and then create new folders for each lobby inside of that. And those lobby folders can contain the players, and settings for those lobbies. This lets you easily reference those things from GUI’s in localscripts and in the server scripts.

The flow would look something like

  1. A player opens up the lobby browser, The LocalScript driving the GUI can look at the replicatedStorage.Lobbies folder’s children to show a list of the current lobbies.
  2. If the player creates a new lobby he would fire a createLobby remoteEvent any other info like desired name that a server script would be connected to and the server would then create a new lobby folder inside of replicatedStorage.Lobbies.
  3. Similar to what you have now a joinLobby remoteEvent for when player wants to join an existing lobby would add that player into the lobby’s player list.
  4. Similar thing for leaving a lobby, server script handling the leave Event would remove the player from the lobby’s player list.

Lobby folder structure could be something like:

ReplicatedStorage
    -Lobbies
        -Bob's Lobby
            -Players
               -Bob (you could do something like an IntValue that's name is their username and the value is their userId for easy lookups for their thumbnails and whatever)
               -Player2
          -Settings
            -Map = Map1

Then have a Gui with a LocalScript that looks at that structure to show the lobbies/how many players it has/what it’s settings are.

1 Like

I already have a working system that is fairly simple. Can you elaborate the part about adding “Player” then the parameters. Because I added it, it didn’t seem to do anything. It just messed up the script by making the existing params not working.

I would look over Remote events and callbacks | Documentation - Roblox Creator Hub
I was talking about the

Client	RemoteEvent:FireServer(args)
Server	RemoteEvent.OnServerEvent:Connect(function(player, args))

Part where I think your main issue is how you’re trying to pass “Owner” as the first parameter in your Event handler, where really that’s going to be the Player the event came from. And you don’t have to pass the player back since that gets added automaticlally.
So where you have:

	game.ReplicatedStorage.JoinPlayer:Fire(Owner, JoinCount, player)

I would change it to

	game.ReplicatedStorage.JoinPlayer:Fire(Owner, JoinCount)

And on the server side change it to:

game.ReplicatedStorage.JoinPlayer.Event:Connect(function(player, Owner, JoinCount) 
1 Like

I don’t know what you are saying. I am just using a bindable event from the person who clicked join, to the owner. But when I receive the event it seems to take on the client of the sender. Shouldn’t the local script apply to the person that the Ui is in? If so, how do I make it do that. are there any things I should know about. Would I need the local script that receives the event only to be in the owners Ui, and not just check if the client is the owner?

Ok, so it sounds like you might not be familiar with the difference between Client and Server
Would be worth it to browse Client-server runtime | Documentation - Roblox Creator Hub

If you are using a BindableEvent, and not a RemoteEvent then that’s why it’s showing up for the player who joined it. BindableEvents only work on the same side of the Client/Server boundary.
So if you’re firing a BindableEvent from a LocalScript (that would be on the Client side) then it’s only going to fire for that same Client (the same Player in this case).

To communicate things one player did to another it would need to go through the server, using a RemoteEvent.
So Player1 Fires RemoteEvent “joinLobby”. A Script (not a LocalScript, but a Script that runs on the server, and locates somewhere like SreverScriptService where server scripts can run) would have to Connect to that RemoteEvent and then send another RemoteEvent to the other players in the lobby.

That’s why that system of using the ReplicatedStorage and RemoteEvents I described earlier is the general way of doing something like this.

Thank you, I didn’t really know that bindable events only fired within one client.