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.
This creates a variable for player 1 and player 2, these are called Tables
I believe.
player1 = {}
player2 = {}
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
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?
So how does this work exactly?
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.
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
Will I be able to use a player in that dictionary table in other scripts?
no but you can change it, check out the message again, iβll be doing to others codes can access
to access in other code you can do this:
shared.players[1]
well i got to go for now. But ill come and try whatever you send.
ok!ββββββββγ €ββββββββγ €ββββββββγ €ββββββββγ €ββββββββγ €ββββββββγ €ββββββββγ €ββββββββγ €ββββββββγ €ββββββββγ €ββββββββγ €ββββββββγ €ββββββββγ €ββββββββγ €ββββββββγ €ββββββββγ €ββββββββγ €ββββββββγ €ββββββββγ €