I have a Local script that fires a Players name in a remote event, and then a server script that gets the Players name and prints it in the output. For some reason though, if there are any more than 1 player in the server, it prints every name 3 times.
Here’s the scripts + what I see in the output
Below is the Local Script, it first intercepts a value from another script that fires a folder that has each player within it, (value)
game.ReplicatedStorage.TestEvent.OnClientEvent:Connect(function(value)
if #value >= 1 then
for i , v in ipairs(value) do
Names = v.Name
local player= game.Players:GetChildren(Names)
game.ReplicatedStorage.PrintName:FireServer(Names)
end
end)
This is your script with everything corrected and comments
how is your client event fired?
game.ReplicatedStorage.TestEvent.OnClientEvent:Connect(function(value)
--if #value >= 1 then -- you don't need to check the number it will only loop if values has atleast 1
local Names = {} -- setup empty table to hold the names
for i , v in ipairs(value) do -- loop through the values table
Names[i] = v.Name -- use i as key set name here
local player= game.Players:FindFirstChild(v.Name) -- not sure why you are gettting player but this is how you would find it by name from value table
end
game.ReplicatedStorage.PrintName:FireServer(Names) -- send the Names table to server I would think this needs to go outside of the for loop when it finishes the names table
end)
game.ReplicatedStorage.PrintName.OnServerEvent:Connect(function(Player, PlayerNames) -- as above need player to be first varaible on server always in event
print(PlayerNames) -- print names table from client
end)
Edited the fire server to be outside the for loop after setting up the full names table
for i,player in pairs(game.Players:GetChildren()) do
local value = game.Workspace.PlayersLeft:GetChildren()
game.ReplicatedStorage.TestEvent:FireClient(player, value)
you said you’re firing the client from the server,then that works
local player = game.Players.LocalPlayer
local value = game.Workspace.PlayersLeft:GetChildren()
game.ReplicatedStorage.TestEvent:FireClient(player, value)
A BoolValue is in each player that determines whether they died during the round or not, and if they didn’t die the event fires. (Also, the PlayersLeft in workspace is a folder that houses each players string value. If they die during the round it gets removed.)
if Dead.value == false and InRound.Value == false then
for i,player in pairs(game.Players:GetPlayers()) do
local value = game.Workspace.PlayersLeft:GetChildren()
game.ReplicatedStorage.TestEvent:FireClient(player, value)
That code is what I have right now, basically it works for me if I’m the only player, but when I do the local test with 2 players it prints out the winner 4 times in a row. It’s not the same as it was before, as it only prints the winner instead of all players, but it still isn’t only printing once.