I'm making a 2 player game where I want the first player to join to become player 1 on the leaderboards, and the second to become player 2
it selects player 1 just fine, but it wont even give the second player any stats.
local player1
local player2
function Onplayerentered(player)
player1:Disconnect()
print("P1 Chosen")
local leaderstats = Instance.new("IntValue")
leaderstats.Parent = player
leaderstats.Value = 0
leaderstats.Name = "leaderstats"
local P1 = Instance.new("IntValue")
P1.Parent = leaderstats
P1.Name = "Player 1" -- Put name here
P1.Value = 1 -- Put the starting Value#
local P2 = Instance.new("IntValue")
P2.Parent = leaderstats
P2.Name = "Player 2" -- Put name here
P2.Value = 0 -- Put the starting Value#
end
function Onplayerentered2(player)
player2:Disconnect()
print("P2 Chosen")
local leaderstats = Instance.new("IntValue")
leaderstats.Parent = player
leaderstats.Value = 0
leaderstats.Name = "leaderstats"
local P1 = Instance.new("IntValue")
P1.Parent = leaderstats
P1.Name = "Player 1" -- Put name here
P1.Value = 0 -- Put the starting Value#
local P2 = Instance.new("IntValue")
P2.Parent = leaderstats
P2.Name = "Player 2" -- Put name here
P2.Value = 1 -- Put the starting Value#
end
player1 = game.Players.ChildAdded:Connect(Onplayerentered)
if player1.Connected == false then
player2 = game.Players.ChildAdded:Connect(Onplayerentered2)
end

1 comment
If I do just if player1 then, it chooses both P1 and P2 when just 1 player joins, but when I do if player1.Connected == nil then it has the same problem as before..