|
| 08 Apr 2014 09:54 AM |
So I have a round script, that loops. It works when I play in solo mode (Studio) All I do is change the minimum players to 1 instead of 2. Here it is:
while wait() do if game.Players.NumPlayers > 1 then while wait() do 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) 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() knife.Parent = game.Players.LocalPlayer.Backpack game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "Round In Progress..." game.Players.LocalPlayer.Character.Torso.CFrame = CFrame.new(randomCoor) wait(60) game.Players.LocalPlayer.Character.Humanoid.Health = 0 wait(5) game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "Round Finished!"
end end if game.Players.NumPlayers < 2 then game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "This game requires 2+ Players!" end end
So the SurfaceGui gets stuck at: "Spawning Players" When more than 1 people join in-game. (I change the minimum to 2 before updating) Can you guys see anything wrong with it? I may be wrong but I'm thinking the LocalPlayer thing isn't entirely working :\ |
|
|
| Report Abuse |
|
|
|
| 08 Apr 2014 10:05 AM |
| This works in studio cause they can get LocalPlayers, you need LocalScripts in Server-Side. However, LocalScripts do not run in workspace in server-side. |
|
|
| Report Abuse |
|
|
|
| 08 Apr 2014 10:06 AM |
knife.Parent = game.Players.LocalPlayer.Backpack
theres your problem,LocalPlayer can only be accessed via LocalScript |
|
|
| Report Abuse |
|
|
|
| 08 Apr 2014 10:08 AM |
| So how can I get all the players to be affected by this script? |
|
|
| Report Abuse |
|
|
|
| 08 Apr 2014 10:09 AM |
for I,v in pairs(game.Players:GetPlayers()) do knife:clone().Parent = v:WaitForChild("Backpack") end
replace the line u have with this |
|
|
| Report Abuse |
|
|
|
| 08 Apr 2014 10:11 AM |
for i,v in pairs(game.Players:GetPlayers()) do knife:Clone().Parent = v.Backpack --By the time the script gets to this part all backpacks are loaded end |
|
|
| Report Abuse |
|
|
|
| 08 Apr 2014 10:13 AM |
WaitForChild("Backpack") is safer though,what is someone joins the instant the knife is cloning?
the script will ultimately error without precautions
just use WaitForChild
if its already there,it parents it,if its not,it waits
its safe |
|
|
| Report Abuse |
|
|
| |
|
|
| 08 Apr 2014 10:14 AM |
Maybe tis' would help
v.Backpack:loadstring() |
|
|
| Report Abuse |
|
|
|
| 08 Apr 2014 10:15 AM |
Working script:
while wait() do if game.Players.NumPlayers > 1 then while wait() do 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) 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() for _,v in pairs(game.Players:GetPlayers()) do knife.Parent = v:WaitForChild("Backpack") end game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "Round In Progress..." game.Players.LocalPlayer.Character.Torso.CFrame = CFrame.new(randomCoor) wait(60) game.Players.LocalPlayer.Character.Humanoid.Health = 0 wait(5) game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "Round Finished!"
end end
if game.Players.NumPlayers < 2 then game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "This game requires 2+ Players!" end end |
|
|
| Report Abuse |
|
|
|
| 08 Apr 2014 10:17 AM |
for I,v in pairs(game.Players:GetPlayers()) do local randomCoor = coordinates[math.random(#coordinates)] local knife = game.ServerStorage.Knife:Clone() knife.Parent = v:WaitForChild("Backpack") game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "Round In Progress..." c = v.Character or v.CharacterAdded:wait() c.Torso.CFrame = CFrame.new(randomCoor) end wait(60) for I,v in pairs(game.Players:GetPlayers()) do c = v.Character or v.CharacterAdded:wait() v.Character.Humanoid.Health = 0 end
|
|
|
| Report Abuse |
|
|
|
| 08 Apr 2014 10:22 AM |
| You guys didn't even realize I used LocalPlayer to teleport the players and to kill them lol, i'll just do the same thing though. |
|
|
| Report Abuse |
|
|
|
| 08 Apr 2014 10:23 AM |
^I realized,so I fixed it^
cant use LocalPlayer from regular script
and in localscript in startergui itd get one person |
|
|
| Report Abuse |
|
|
|
| 08 Apr 2014 10:24 AM |
Oh, island posted.
Thanks for all your help guys :) |
|
|
| Report Abuse |
|
|
|
| 08 Apr 2014 10:27 AM |
*dances
oh,ppl r looking..
*stops
np!
*looks around..
... *dances |
|
|
| Report Abuse |
|
|
|
| 08 Apr 2014 10:40 AM |
| Actually Island, I was the one who told him what was the problem, first. |
|
|
| Report Abuse |
|
|
|
| 08 Apr 2014 10:41 AM |
^that,is a true statement
but I ultimately fixed it..
yknow what,lets not argue
we both helped period |
|
|
| Report Abuse |
|
|