Making 2 remotes only fire for players in a table

Hello.

I have a party system script that teleports players in a table to a reserved server.

I also want this script to show a GUI and play a sound for those players.

The teleporting only works for the players in the table, but the GUI and sound show and play for every player on the server.

Here is the part of the script that has this problem:

local playersToTP = {}

			for i, playerInParty in pairs(game.ReplicatedStorage.Parties[value1].Players:GetChildren()) do

				table.insert(playersToTP, game.Players[playerInParty.Value])
			end
			for _, d in pairs(game.Players:GetPlayers(playersToTP)) do
				d.Character.Humanoid.WalkSpeed = 0
				d.Character.Humanoid.JumpPower = 0
--Fires for everyone 
				game.ReplicatedStorage.LoadingSound:FireClient(d)
				game.ReplicatedStorage.TpEvent:FireClient(d)	
--              ^
			end

			local tpOptions = Instance.new("TeleportOptions")
			tpOptions.ShouldReserveServer = true

			tps:TeleportAsync(placeId, playersToTP, tpOptions)

There are no errors in the output.

How do I fix this problem?

2 Likes

How did you define the dmg value?

the dmg was meant to be d as well, my mistake.

The reason everyone is hearing the sound is because you are looping through a table which was created via :GetPlayers() which returns all the players currently in the game

To stop that instead loop through the playersToTP table so you would change this

for _, d in pairs(game.Players:GetPlayers(playersToTP)) do
				d.Character.Humanoid.WalkSpeed = 0
				d.Character.Humanoid.JumpPower = 0
--Fires for everyone 
				game.ReplicatedStorage.LoadingSound:FireClient(d)
				game.ReplicatedStorage.TpEvent:FireClient(d)	
--              ^
			end

You would do

for _, d in pairs(playersToTp) do
				d.Character.Humanoid.WalkSpeed = 0
				d.Character.Humanoid.JumpPower = 0
--Fires for everyone 
				game.ReplicatedStorage.LoadingSound:FireClient(d)
				game.ReplicatedStorage.TpEvent:FireClient(d)	
--              ^
			end

lmk how this goes

Changing that managed to make it work. Thanks for the help.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.