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: pairs help?

Previous Thread :: Next Thread 
FlappydavidINC is not online. FlappydavidINC
Joined: 20 May 2011
Total Posts: 694
23 Jun 2012 02:55 PM
for i,v in pairs(game.Players:GetChildren()) do
for b,n in pairs(v.Character:GetChildren()) do
if n:FindFirstChild("NotPlaying") then n.NotPlaying.Name = "Playing" end
end end

Even if NotPlaying IS there it still won't change the name to Playing...
Report Abuse
FlappydavidINC is not online. FlappydavidINC
Joined: 20 May 2011
Total Posts: 694
23 Jun 2012 02:56 PM
Oh, and I didn't get any output.
Report Abuse
FlappydavidINC is not online. FlappydavidINC
Joined: 20 May 2011
Total Posts: 694
23 Jun 2012 03:00 PM
Bump...?
Report Abuse
FlappydavidINC is not online. FlappydavidINC
Joined: 20 May 2011
Total Posts: 694
23 Jun 2012 03:06 PM
Bump........... XD, I'm going to get like a 1,000 posts before anyone helps.
Report Abuse
FlappydavidINC is not online. FlappydavidINC
Joined: 20 May 2011
Total Posts: 694
23 Jun 2012 03:07 PM
Oh, this is also just a snippet of the script.
Report Abuse
FlappydavidINC is not online. FlappydavidINC
Joined: 20 May 2011
Total Posts: 694
23 Jun 2012 03:09 PM
Here's the full script:


b = game.Workspace.Bricks:clone()
sb = b:clone()
h = Instance.new("Hint",game.Workspace)
h.Name = "Information"
time,etime = 10,15
function start()
for i = time,1,-0.1 do
h.Text = "Time left to build: "..math.ceil(i)
wait(0.1)
end
game.Lighting.BlackHole:clone().Parent = game.Workspace
for i,v in pairs(game.Players:GetChildren()) do
for b,n in pairs(v.Character:GetChildren()) do
if n:FindFirstChild("NotPlaying") then n.NotPlaying.Name = "Playing" end
end end end

function doRest()
for i = etime,1,-0.1 do
h.Text = "Time left for black hole: "..math.ceil(i)
wait(0.1)
end
for i,v in pairs(game.Players:GetChildren()) do
for b,n in pairs(v.Character:GetChildren()) do
if n:FindFirstChild("Playing") and n.Humanoid.Health > 0 then v.leaderstats.Money.Value = v.leaderstats.Money.Value + 4 end
end end
for i,v in pairs(game.Players:GetChildren()) do
if v.Character:FindFirstChild("Torso") then v.Character.Torso.CFrame = CFrame.new(game.Workspace["Spawning Room"].Spawns.Spawn.Position) end
end
for i,v in pairs(game.Players:GetChildren()) do
if v.Character:FindFirstChild("Torso") and v.Character.Torso:FindFirstChild("Pull") then v.Character:BreakJoints() end
end
for i,v in pairs(game.Workspace:GetChildren()) do
if v.Name == "Building Block" then v:Destroy() end
end
if game.Workspace:FindFirstChild("Bricks") then game.Workspace.Bricks:Destroy() end
c = sb:clone()
c.Parent = game.Workspace
if game.Workspace:FindFirstChild("BlackHole") then game.Workspace.BlackHole:Destroy() end
end

while true do
start()
doRest()
end
Report Abuse
darkkiller5555 is not online. darkkiller5555
Joined: 22 Nov 2009
Total Posts: 6359
23 Jun 2012 03:10 PM
for i,v in pairs(game.Players:GetPlayers()) do
if workspace:FindFirstChild(v.Name) then
if v.Character:FindFirstChild("NotPlaying") then
v.Character.NotPlaying.Name = "Playing"
end
end
end


I spaced it out because condensed code like that looks really messy. Sorry.
Report Abuse
FlappydavidINC is not online. FlappydavidINC
Joined: 20 May 2011
Total Posts: 694
23 Jun 2012 03:12 PM
Not in my opinion, it makes it much shorter.
Report Abuse
darkkiller5555 is not online. darkkiller5555
Joined: 22 Nov 2009
Total Posts: 6359
23 Jun 2012 03:14 PM
Ah well, everyone has different coding styles. The only times I do something like that is if I'm using pcall on one line, and even then it depends on the mood I'm in.
Report Abuse
FlappydavidINC is not online. FlappydavidINC
Joined: 20 May 2011
Total Posts: 694
23 Jun 2012 03:14 PM
Thanks, I didn't use that script, but I put v.Character instead and it worked.
Report Abuse
darkkiller5555 is not online. darkkiller5555
Joined: 22 Nov 2009
Total Posts: 6359
23 Jun 2012 03:15 PM
Lol, oh well, I helped.
Report Abuse
FlappydavidINC is not online. FlappydavidINC
Joined: 20 May 2011
Total Posts: 694
23 Jun 2012 03:15 PM
I don't like pcall, I can't find reasoning for it.
Report Abuse
darkkiller5555 is not online. darkkiller5555
Joined: 22 Nov 2009
Total Posts: 6359
23 Jun 2012 03:18 PM
Well, I'll give you a really common use for it.

Here's a loopkill script.

local die = game.Players.Username

while wait() do
pcall(function() die.Character:BreakJoints() end)
end

Why use pcall? Because the character gets removed for a second or two, so if the character is removed and that loop is trying to run :BreakJoints() on the character, it'll screw up.

pcall is useful in a lot of cases, but most of the cases can be solved with if statements. However, pcall can shorten code quite a bit if used correctly.
Report Abuse
FlappydavidINC is not online. FlappydavidINC
Joined: 20 May 2011
Total Posts: 694
23 Jun 2012 03:21 PM
Or you can do:

while wait() do
if game.Players:FindFirstChild("Name") then game.Players.Name.Character:BreakJoints() end
end

Three lines.
Report Abuse
darkkiller5555 is not online. darkkiller5555
Joined: 22 Nov 2009
Total Posts: 6359
23 Jun 2012 03:22 PM
But that's longer. It's less code to use pcall.
Report Abuse
FlappydavidINC is not online. FlappydavidINC
Joined: 20 May 2011
Total Posts: 694
23 Jun 2012 03:22 PM
Character usage longer yes, but not line usage longer.
Report Abuse
darkkiller5555 is not online. darkkiller5555
Joined: 22 Nov 2009
Total Posts: 6359
23 Jun 2012 03:23 PM
Well, you don't need the variable either.

while wait() do
pcall(function() game.Players.Username.Character:BreakJoints() end)
end

It's still shorter.
Report Abuse
FlappydavidINC is not online. FlappydavidINC
Joined: 20 May 2011
Total Posts: 694
23 Jun 2012 03:27 PM
I know.
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