How can I make a variable for player1 and player2?

Title says it all.
How can I make a variable for player 1 and player 2? I want to make a 1v1 fighting game and I want to make a variable of the players.

1 Like

This creates a variable for player 1 and player 2, these are called Tables I believe.

player1 = {}
player2 = {}
1 Like

check this out!

-- ServerScriptService

shared.players = {}
local count = 0

game:GetService('Players').PlayerAdded:Connect(function(plr)
β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€if count > 2 then
β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€plr:Kick('Server is full')
β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€return
β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€end
β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€count += 1
β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€shared.players[count] = plr
β€Žβ€Žend)

to access the players only do this

players[1] -- for player 1 or 2 for player 2
1 Like

So If I make a code of player 1 always facing at player 2, will the script understand who player 1 and player 2 is?

1 Like

So how does this work exactly?

1 Like

Swift2.x

let player1 = [1: "foo", 2: "bar"]
let player2 = [1: "foo", 2: "bar"]

if player1 == player2 {
    print("player1 and player2 is equal")
}

Swift3.x

let player1 = [1: "foo", 2: "bar"]
let player2 = [1: "foo", 2: "bar"]

if player1 == player2 {
    print("player1 and player2 is equal")
}

It checks if player1 and player2 are equal.

1 Like

basically, when the players join, the server adds the player to a Dictionary Table and adds +1 to server count, if the server count is more than 2, the players that have been joined will be kicked, you can use PlayerRemoving to subtract the count variable

1 Like

Will I be able to use a player in that dictionary table in other scripts?

1 Like

no but you can change it, check out the message again, i’ll be doing to others codes can access

1 Like

to access in other code you can do this:

shared.players[1]
1 Like

well i got to go for now. But ill come and try whatever you send.

1 Like

ok!β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€β€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žβ€Žγ…€

2 Likes