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

This script partially works, help me find out what's wrong?

Asked by 10 years ago

I have a round script, it loop checks if there are >1 player's, or <1 players, and if there's 2 players, starts the round. It works fine, except it teleports 1 player, instead of all of them. Here's the script, try to tell me what's wrong please, I can't check output because it needs 2+.

while wait() do
    if game.Players.NumPlayers > 1 then
            wait(5)

            game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "Starting New Round..."

            wait(3)

            game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "Spawning Players..."

            wait(1)

            for i,v in pairs(game.Players:GetPlayers()) do
            local coordinates = {Vector3.new(-80.9, 3.2, -286.5), Vector3.new(1.64, 3.2, -179.7), Vector3.new(83.5, 3.2, -287.5), Vector3.new(2.44, 3.2, -396.5)}               
            local randomCoor = coordinates[math.random(#coordinates)]
            local knife = game.ServerStorage.Knife:Clone()
            v.Character.Torso.CFrame = CFrame.new(randomCoor)
            v.Character.Torso.Anchored = true
            knife.Parent = v.Backpack
            wait(4)
            v.Character.Torso.Anchored = false
            end

            wait(60)

            for i, v in pairs(game.Players:GetChildren()) do 
            v.Character.Humanoid.Health = 0
            end

            wait(5)

            game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "Round Finished!"

            end

    if game.Players.NumPlayers < 2 then
        game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "This game requires 2+ Players."
        wait(1)
        game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "This game requires 2+ Players.."
        wait(1)
        game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "This game requires 2+ Players..."
        wait(1)
    end
end


Can you try to see what's wrong? It only teleports 1 player. It kills all the players though, and gives all players the knife, when the round begins.

2 answers

Log in to vote
1
Answered by 10 years ago

Change this loop:

for i,v in pairs(game.Players:GetPlayers()) do
            local coordinates = {Vector3.new(-80.9, 3.2, -286.5), Vector3.new(1.64, 3.2, -179.7), Vector3.new(83.5, 3.2, -287.5), Vector3.new(2.44, 3.2, -396.5)}              
            local randomCoor = coordinates[math.random(#coordinates)]
            local knife = game.ServerStorage.Knife:Clone()
            v.Character.Torso.CFrame = CFrame.new(randomCoor)
            v.Character.Torso.Anchored = true
            knife.Parent = v.Backpack
            wait(4)
            v.Character.Torso.Anchored = false
end

In this:

for i,v in pairs(game.Players:GetChildren()) do
            local coordinates = {Vector3.new(-80.9, 3.2, -286.5), Vector3.new(1.64, 3.2, -179.7), Vector3.new(83.5, 3.2, -287.5), Vector3.new(2.44, 3.2, -396.5)}              
            local randomCoor = coordinates[math.random(#coordinates)]
            local knife = game.ServerStorage.Knife:Clone()
            v.Character.Torso.CFrame = CFrame.new(randomCoor)
            v.Character.Torso.Anchored = true
            knife.Parent = v.Backpack
            wait(4)
            v.Character.Torso.Anchored = false
            wait(0.3) -- Add a delay of 0.3 second before spawning each player, it will cause issues like: not teleporting, dying or falling from the map =)
end

Also for check functions that need 2+ players, you can start a local server by using "Start Server (F7)" and open client as many as the players needed using "Start Client (Alt+F7)" or something like this =D

0
Thanks, I will try this :) systematicaddict 295 — 10y
0
If it does't work then we need to rewrite the entire code! alessandro112 161 — 10y
0
I got it, instead of Torso.CFrame, use Character:MoveTo(randomCoor), because if you move ONLY the torso, the player will be killed =) alessandro112 161 — 10y
Ad
Log in to vote
-1
Answered by 10 years ago

In line 2 change:

    if game.Players.NumPlayers > 1 then

To like say you want 5 to go change it to:

    if game.Players.NumPlayers > 5 then

Should work

Answer this question