I would like to explain to you what was wrong in case you will have similiar problem to me in the future
There was 3 players in the game. for i, v in pairs(game.Players:GetChildren() do its a loop that replicates through every player so we can say that it repeats the same function 3 times (because thats how many players are in the game there can be 4 players and it will be repeated 4 times) So it was repeating 3 times and every time it was also turning on a function in module script which added the same player over and over for 3 times so all i had to do is to put the function i wanted to be fired once outside of the loop
Hope you will understand, its kinda messy because english is my seconds language.
Im making a Lobby Creating Gui.
When there's 3 players in the game it's duplicating 3 times. I think that it may be because of the player count, but i dont know how to change it can anybody tell :(?
When i click join the same players is added to a table few times I even tried putting "print" and it was printing multiple times too
I have no idea why this is happening so maybe you know :(?
Any help would be appreciated
local script in a button
local LeaveRoomRemote = game.ReplicatedStorage:WaitForChild("LobbyCreatorRemotes").LeaveRoom
script.Parent.MouseButton1Down:Connect(function()
local PlayerWhoIsLeaving = game.Players.LocalPlayer
local RoomPlayerIsLeaving = script.Parent.Parent.Name
LeaveRoomRemote:FireServer(PlayerWhoIsLeaving, RoomPlayerIsLeaving)
end)
Script in ServerScriptService (This is only the function responsible for player joining to a new room)
PlayerJoinRemote.OnServerEvent:Connect(function(Plr, JoiningClient, RoomName, CreatorOfTheRoom)
for i, v in pairs(game.Players:GetChildren()) do
if v then
local GuiToCheck = v.PlayerGui.MenuGui.Rooms:FindFirstChild(RoomName)
local TheCreatorOfTheRoomNewPlayerJoined = CreatorOfTheRoom
local CreatorManagerRoomGui = game.Players:FindFirstChild(TheCreatorOfTheRoomNewPlayerJoined).PlayerGui.MenuGui:FindFirstChild(RoomName.."Manager")
local Plr1Pic = GuiToCheck.Plr1
local Plr2Pic = GuiToCheck.Plr2
local Plr3Pic = GuiToCheck.Plr3
local Plr4Pic = GuiToCheck.Plr4
local RoomModule = require(CreatorManagerRoomGui:WaitForChild("RoomModule"))
RoomModule.AddPlayer(JoiningClient)
print("DDddDDdddDDddDDddDDddDDddDDddDDddDDdd")
if Plr1Pic.Image == "None" then
Plr1Pic.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&username="..JoiningClient.Name
Plr1Pic.PlayerName.Value = JoiningClient.Name
CreatorManagerRoomGui.Plr1.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&username="..JoiningClient.Name
CreatorManagerRoomGui.Plr1.PlayerName.Value = JoiningClient.Name
else
if Plr2Pic.Image == "None" then
Plr2Pic.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&username="..JoiningClient.Name
Plr2Pic.PlayerName.Value = JoiningClient.Name
CreatorManagerRoomGui.Plr2.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&username="..JoiningClient.Name
CreatorManagerRoomGui.Plr2.PlayerName.Value = JoiningClient.Name
else
if Plr3Pic.Image == "None" then
Plr3Pic.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&username="..JoiningClient.Name
Plr3Pic.PlayerName.Value = JoiningClient.Name
CreatorManagerRoomGui.Plr3.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&username="..JoiningClient.Name
CreatorManagerRoomGui.Plr3.PlayerName.Value = JoiningClient.Name
else
if Plr4Pic.Image == "None" then
Plr4Pic.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&username="..JoiningClient.Name
Plr4Pic.PlayerName.Value = JoiningClient.Name
CreatorManagerRoomGui.Plr4.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&username="..JoiningClient.Name
CreatorManagerRoomGui.Plr4.PlayerName.Value = JoiningClient.Name
end
end
end
end
end
end
end)
Pls help :(
