K so I'm glad to see your doing stuff with the script I wrote for you, YAY!! Except there are a few things that need to be added, aww :(. First off, I suggest you combine the two conditional statements into one function. So that we could shorten down the script and make it more efficient. This first step would look like this:
local target1 = CFrame.new(0 - 178, 79, 0)
local target2 = CFrame.new(0 - 178, 205, 0)
function PlayerChanged()
local PlayerCount = #(game.Players:GetChildren())
local players = game.Players:GetChildren()
if PlayerCount > 1 then
for i, v in pairs(players) do
repeat wait() until v.Character ~= nil
if v.Character.Humanoid.Health ~= 0 then
game.Workspace.Spawn.Spawn.Enabled = true
game.Workspace.Lobby.Spawn.Enabled = false
game.ReplicatedStorage.arena1.Parent = workspace
v.Character.Torso.CFrame = target1
end
end
end
if PlayerCount < 1 then
for i, v in pairs(players) do
repeat wait() until v.Character ~= nil
if v.Character.Humanoid.Health ~= 0 then
game.Workspace.Spawn.Spawn.Enabled = false
game.Workspace.Lobby.Spawn.Enabled = true
game.Workspace.arena1.Parent = game.ReplicatedStorage
v.Character.Torso.CFrame = target2
end
end
end
end
Now there's a TON that I changed with the script, I don't have the time to explain. The main thing is, I've created a new function that will hold both conditional statements. Now you said the script stopped working every time a player joins the server. This brings me to step two, which is calling function every time a player is added to the game . We'd use a connection line. If you don't already know what this is, there basically function callers (something that starts the function) if a certain event is fired (AKA if something happens in the game, like if a player touches a part, or if a player has died). We'd use two connection lines: the first one to start up the function if a player joins the game. And if a player leaves the game. These two connection lines would look something like this: 1: game.Players.PlayerAdded:connect(PlayerChanged) 2: game.Players.PlayerRemoving:connect(PlayerChanged) . So when the event is fired, we start up the function that is called "PlayerChanged". This edit would look like this:
function PlayerChanged(player)
local PlayerCount = #(game.Players:GetChildren())
local players = game.Players:GetChildren()
if PlayerCount > 1 then
for i, v in pairs(players) do
repeat wait() until v.Character ~= nil
if v.Character.Humanoid.Health ~= 0 then
game.Workspace.Spawn.Spawn.Enabled = true
game.Workspace.Lobby.Spawn.Enabled = false
game.ReplicatedStorage.arena1.Parent = workspace
v.Character.Torso.CFrame = target1
end
end
end
if PlayerCount < 1 then
for i, v in pairs(players) do
repeat wait() until v.Character ~= nil
if v.Character.Humanoid.Health ~= 0 then
game.Workspace.Spawn.Spawn.Enabled = false
game.Workspace.Lobby.Spawn.Enabled = true
game.Workspace.arena1.Parent = game.ReplicatedStorage
v.Character.Torso.CFrame = target2
end
end
end
end
game.Players.PlayerAdded:connect(PlayerChanged)
game.Players.PlayerRemoving:connect(PlayerChanged)
Sadly were not done yet :). Yes Yes bear with me. So if every time a player enters and the function is called, every player will be teleported to a position. That's a no no! So Instead, we'll only teleport the new player that entered the game, but with still index how many total players there are. So we would take out the iteration that would teleport all the players, and only run the next few lines of code for the player that were specifying (the player that just joined). So the final FINAL product would FINALLY look like THIS:
function PlayerChanged(player)
local PlayerCount = #(game.Players:GetChildren())
local players = game.Players:GetChildren()
if PlayerCount > 1 then
repeat wait() until player.Character ~= nil
if player.Character.Humanoid.Health ~= 0 then
game.Workspace.Spawn.Spawn.Enabled = true
game.Workspace.Lobby.Spawn.Enabled = false
game.ReplicatedStorage.arena1.Parent = workspace
player.Character.Torso.CFrame = target1
end
end
if PlayerCount < 1 then
repeat wait() until player.Character ~= nil
if player.Character.Humanoid.Health ~= 0 then
game.Workspace.Spawn.Spawn.Enabled = false
game.Workspace.Lobby.Spawn.Enabled = true
game.Workspace.arena1.Parent = game.ReplicatedStorage
player.Character.Torso.CFrame = target2
end
end
end
game.Players.PlayerAdded:connect(PlayerChanged)
game.Players.PlayerRemoving:connect(PlayerChanged)
Sorry if this seemed a bit rushed :(. It's 12:00 midnight here don't judge me :)! Anyways hopefully this gave you an idea of what to do. If you have any questions, post a comment below. Again I'm kinda rushed on time soooo. YOUR WELCOME!!!!
1 comment
K I see you tried implenting my script into a working concept. There are a TON of things that are needed to be changed. So please be patient.