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: How to find Children, and examples of While true do?

Previous Thread :: Next Thread 
Paul13379001 is not online. Paul13379001
Joined: 06 Jun 2011
Total Posts: 1384
19 Jan 2013 09:55 PM
Hio. I'm trying to make a script that removes the backpack from a player, but I'm not sure how exactly I would do that, and I'm guessing I would need to find the Children to the Player's section of a game, and need a While true do loop so the script always runs repeatedly even if the player dies?


What are some good examples of how I can use the While true do loop, and how do I find children?
Report Abuse
Paul13379001 is not online. Paul13379001
Joined: 06 Jun 2011
Total Posts: 1384
19 Jan 2013 10:01 PM
while true do
wait(0)

game.Players:FindChildren.Backpack:remove()

end

????
Report Abuse
Jonah13249 is not online. Jonah13249
Joined: 09 Oct 2009
Total Posts: 2105
19 Jan 2013 10:15 PM
while true do
for _, v in pairs(game.Players:GetPlayers()) do
local backpack = v:findFirstChild("Backpack")
if not backpack then return end
backpack:Destroy()
wait()
end
end

~ṡсɾïρτïṉģ hεlρεɾṡ ۩ lυαlεαɾṉεɾṡ ④ øƒвќṃṿј~ ღ ▂▃▅▆█ρεώḋïερïε☄сυτïερïε█▆▅▃▂ღ 【▬】
Report Abuse
Volexity is not online. Volexity
Joined: 16 Jan 2013
Total Posts: 32
19 Jan 2013 10:16 PM
Have you lost your child ?
Report Abuse
MasterROBOGuy1234 is not online. MasterROBOGuy1234
Joined: 20 Dec 2010
Total Posts: 791
19 Jan 2013 10:33 PM
@Volex,
I'm sorry that wasn't funny, because I've heard it so many times...
Report Abuse
Volexity is not online. Volexity
Joined: 16 Jan 2013
Total Posts: 32
19 Jan 2013 10:40 PM
I've heard that so many times...

Even ?
Report Abuse
MasterROBOGuy1234 is not online. MasterROBOGuy1234
Joined: 20 Dec 2010
Total Posts: 791
19 Jan 2013 10:41 PM
Even, Yo mama.
Report Abuse
Volexity is not online. Volexity
Joined: 16 Jan 2013
Total Posts: 32
20 Jan 2013 02:04 AM

Well played...
Report Abuse
eugenevorld is not online. eugenevorld
Joined: 15 Nov 2008
Total Posts: 310
20 Jan 2013 07:00 AM
In my opinion that is not a very efficient way of managing, you should try.

game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(char)
if player.Backpack then player.Backpack:remove() end
end)
end)

This way, the script checks when the player's character respawns and deletes the backpack when it does. An alternative is to check when something is inserted into a player and if that something was a backpack then remove it.

game.Players.PlayerAdded:connect(function(player)
player.ChildAdded:connect(function(child)
if child:IsA("Backpack") then child:remove() end
end)
end)
Report Abuse
eugenevorld is not online. eugenevorld
Joined: 15 Nov 2008
Total Posts: 310
20 Jan 2013 07:02 AM
To answer your question about while loops, it works like this.

while (expression) do
(statement)
end

This means, the expression is first evaluated eg. 1=1, is an expression and 1 does in fact equals one and the statement is executed. However when something like this happens.

n=1
while n=1 do
n=2
end

The above loop will only execute the statement once since the expression is evaluated returning true, but n is changed to two making the expression 2=1 which is not true.

while true do
(statement)
end

The above loop will continuously run as the expression is true which immediately returns true, however a thing to consider is that this will most likely overwhelm studio and crash it as it continuously executes the statement with no ends. A way to prevent this is to...

while true do
wait()
(statement)
end

or

while wait() do
(statement)
end

This way before the statement executes, the loop waits for a bit and then executes the statement which does not bombard studio with never ending statements. "while wait() do", even though wait() is not an expression, it was executed without a problem and therefore returns true. You could also do...

while 5 do
(statement)
end

As the expression was evaluated without a problem and executes the statement. Multiple expressions can be added onto the while loop similar to the if statement.

while (expression) and (expression) or (expression) do
(statement)
end

This way you can control when your statement is executed in specific conditions.
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