Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I fix this error?

Asked by
Jephi 42
9 years ago
local target1 = CFrame.new(0 - 178, 79, 0)
local target2 = CFrame.new(0 - 178, 205, 0)

if #(game.Players:GetChildren()) > 1 then
    for i, player in pairs(game.Players:GetChildren()) do
        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
end

if #(game.Players:GetChildren()) < 1 then
    for i, player in pairs(game.Players:GetChildren()) do
        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

Error: Content failed because HTTP 404 (HTTP/1.1 404 Not Found)

Happens when another person joins. My above script doesn't even work.

0
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. LateralLace 297 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

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!!!!

0
I don't really get how it makes sure that it's just teleporting the NEW player and not all the players. sorry for making you type so much :( Jephi 42 — 9y
0
Also. it doesn't seem to teleport the original player who joined. Jephi 42 — 9y
0
Also. when the other player leaves it doesn't transfer arena1 into ReplicatedStorage. Jephi 42 — 9y
Ad

Answer this question