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 11 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+.

01while wait() do
02    if game.Players.NumPlayers > 1 then
03            wait(5)
04 
05            game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "Starting New Round..."
06 
07            wait(3)
08 
09            game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "Spawning Players..."
10 
11            wait(1)
12 
13            for i,v in pairs(game.Players:GetPlayers()) do
14            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)}              
15            local randomCoor = coordinates[math.random(#coordinates)]
View all 44 lines...

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 11 years ago

Change this loop:

01for i,v in pairs(game.Players:GetPlayers()) do
02            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)}             
03            local randomCoor = coordinates[math.random(#coordinates)]
04            local knife = game.ServerStorage.Knife:Clone()
05            v.Character.Torso.CFrame = CFrame.new(randomCoor)
06            v.Character.Torso.Anchored = true
07            knife.Parent = v.Backpack
08            wait(4)
09            v.Character.Torso.Anchored = false
10end

In this:

01for i,v in pairs(game.Players:GetChildren()) do
02            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)}             
03            local randomCoor = coordinates[math.random(#coordinates)]
04            local knife = game.ServerStorage.Knife:Clone()
05            v.Character.Torso.CFrame = CFrame.new(randomCoor)
06            v.Character.Torso.Anchored = true
07            knife.Parent = v.Backpack
08            wait(4)
09            v.Character.Torso.Anchored = false
10            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 =)
11end

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 — 11y
0
If it does't work then we need to rewrite the entire code! alessandro112 161 — 11y
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 — 11y
Ad
Log in to vote
-1
Answered by 11 years ago

In line 2 change:

1if game.Players.NumPlayers > 1 then

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

1if game.Players.NumPlayers > 5 then

Should work

Answer this question