|
| 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 |
|
|
|
| 19 Jan 2013 10:01 PM |
while true do wait(0)
game.Players:FindChildren.Backpack:remove()
end
???? |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| Joined: 16 Jan 2013 |
| Total Posts: 32 |
|
|
| 19 Jan 2013 10:16 PM |
| Have you lost your child ? |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| Joined: 16 Jan 2013 |
| Total Posts: 32 |
|
|
| 19 Jan 2013 10:40 PM |
I've heard that so many times...
Even ? |
|
|
| Report Abuse |
|
|
| |
|
Volexity
|
  |
| Joined: 16 Jan 2013 |
| Total Posts: 32 |
|
| |
|
|
| 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 |
|
|
|
| 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 |
|
|