generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: while wait() do

Previous Thread :: Next Thread 
DeSpizer27 is not online. DeSpizer27
Joined: 13 Jul 2012
Total Posts: 2679
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
WickedSiege is not online. WickedSiege
Joined: 03 Oct 2011
Total Posts: 3039
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
islandmaker2012 is online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
08 Apr 2014 10:06 AM
knife.Parent = game.Players.LocalPlayer.Backpack

theres your problem,LocalPlayer can only be accessed via LocalScript
Report Abuse
DeSpizer27 is not online. DeSpizer27
Joined: 13 Jul 2012
Total Posts: 2679
08 Apr 2014 10:08 AM
So how can I get all the players to be affected by this script?
Report Abuse
islandmaker2012 is online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
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
WickedSiege is not online. WickedSiege
Joined: 03 Oct 2011
Total Posts: 3039
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
islandmaker2012 is online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
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
islandmaker2012 is online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
08 Apr 2014 10:13 AM
what if*
Report Abuse
WickedSiege is not online. WickedSiege
Joined: 03 Oct 2011
Total Posts: 3039
08 Apr 2014 10:14 AM
Maybe tis' would help

v.Backpack:loadstring()
Report Abuse
WickedSiege is not online. WickedSiege
Joined: 03 Oct 2011
Total Posts: 3039
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
islandmaker2012 is online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
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
DeSpizer27 is not online. DeSpizer27
Joined: 13 Jul 2012
Total Posts: 2679
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
islandmaker2012 is online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
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
DeSpizer27 is not online. DeSpizer27
Joined: 13 Jul 2012
Total Posts: 2679
08 Apr 2014 10:24 AM
Oh, island posted.

Thanks for all your help guys :)
Report Abuse
islandmaker2012 is online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
08 Apr 2014 10:27 AM
*dances

oh,ppl r looking..

*stops

np!

*looks around..

...
*dances
Report Abuse
WickedSiege is not online. WickedSiege
Joined: 03 Oct 2011
Total Posts: 3039
08 Apr 2014 10:40 AM
Actually Island, I was the one who told him what was the problem, first.
Report Abuse
islandmaker2012 is online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image