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 remove certain things from a table?

Previous Thread :: Next Thread 
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
23 Jun 2013 04:30 PM
I made a script that adds players to a table and then kills them
how would i make it so that it removes the certain player(s) that die from the table?
Also is there a way that could make the script below more efficient?
here's part of my script:
the table is _G.peoplehit


local e = Workspace:GetChildren()
for i = 1,#_G.peoplehit do
if (_G.peoplehit[i] ~= nil) then
local face = (_G.peoplehit[i].Head:findFirstChild("face"))
if face ~= nil then
face.Texture = "http://www.roblox.com/asset/?id=111916219"
while _G.peoplehit[i].Humanoid.Health>0 do
wait()
_G.peoplehit[i].Head.Mesh.Scale = _G.peoplehit[i].Head.Mesh.Scale +Vector3.new(0.01,0.01,0.01)
_G.peoplehit[i].Humanoid.Health = _G.peoplehit[i].Humanoid.Health - 1
end
end
end
end

Thanks
Report Abuse
Unsubstantial is not online. Unsubstantial
Joined: 11 Sep 2012
Total Posts: 872
23 Jun 2013 04:32 PM
table.remove(tablename, KEY)
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
23 Jun 2013 04:33 PM
that kind of helps, but how would i make it apply to certain players that die?
._.
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
23 Jun 2013 04:37 PM
for _,Person in next,_G.peoplehit do
if Person and Person:FindFirstchild[[Head]] then
local Face = Person.Head:FindFirstChild[[face]]
if Face then
Face.Texture= "http://www.roblox.com/asset/?id=111916219"
local Alive = true
Spawn(function()
while Alive do
wait()
Person.Head.Mesh.Scale = Person.Head.Mesh.Scale +Vector3.new(0.01,0.01,0.01)
Person.Humanoid.Health = _Person.Humanoid.Health - 1
end
end)
Person.Humanoid.Died:connect(function()
Alive = false
table.remove(_G.peoplehit,_)
end)
end
end
end
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
23 Jun 2013 04:46 PM
do i have to define _,Person in next? and if i do how? ._.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
23 Jun 2013 04:58 PM
"notsopwnedg

Joined: 07 Nov 2010
Total Posts: 2362
LuaLearners

Re: How to remove certain things from a table?
Posted: 06-23-2013 02:37 PM
for _,Person in next,_G.peoplehit do
if Person and Person:FindFirstchild[[Head]] then
local Face = Person.Head:FindFirstChild[[face]]
if Face then
Face.Texture= "http://www.roblox.com/asset/?id=111916219"
local Alive = true
Spawn(function()
while Alive do
wait()
Person.Head.Mesh.Scale = Person.Head.Mesh.Scale +Vector3.new(0.01,0.01,0.01)
Person.Humanoid.Health = _Person.Humanoid.Health - 1
end
end)
Person.Humanoid.Died:connect(function()
Alive = false
table.remove(_G.peoplehit,_)
end)
end
end
end"



That is one of the worst scripts I have ever seen. LL would be ashamed at that coding style.
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
23 Jun 2013 05:10 PM
Agent, Can u fix it for me :)?
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
23 Jun 2013 05:12 PM
Bump
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
23 Jun 2013 05:14 PM
I would change the way you add people to the table.


function RemovePlayerOnDeath(Table, Player)
ypcall(function()
Player.Character.Humanoid.Died:wait()
Table[Player] = false
end)
end

function Add(Table, Player)
Table[Player] = true
RemovePlayerOnDeath(Table, Player)
end

function PlayerIsAlive(Table, Player)
for _, v in pairs(Table) do
if _ == Player then
return v
end
end
return false
end
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
23 Jun 2013 05:26 PM
Thanks! :D
I don't get the Table[Player] = true part tho
Would I use it like this?:

function touch(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
add(_G.peoplehit,hit.Parent)
end
end

or how?
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
23 Jun 2013 05:31 PM
AFF Any chance you can tell me why it is so horrible so I don't do that again...

Dx
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
23 Jun 2013 05:42 PM
"Thanks! :D
I don't get the Table[Player] = true part tho
Would I use it like this?:

function touch(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
add(_G.peoplehit,hit.Parent)
end
end

or how?"


function touch(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
if game.Players:GetPlayerFromCharacter(hit.Parent) then
Add(_G.peoplehit,game.Players:GetPlayerFromCharacter(hit.Parent))
end
end


Then use the PlayerIsAlive function to see if they are in the table.







"AFF Any chance you can tell me why it is so horrible so I don't do that again...

Dx"

The pairs function exists so you don't have to type 'in next, Table.' Using pairs makes it much cleaner. Using [[ ]] as your string delimiters is terrible, plus the fact that you omitted the parenthesis to your method calls. Those combined are even worse. Using table.remove from a numerical loop is bad because it would skip the next index IIRC.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
23 Jun 2013 05:43 PM
"function touch(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
if game.Players:GetPlayerFromCharacter(hit.Parent) then
Add(_G.peoplehit,game.Players:GetPlayerFromCharacter(hit.Parent))
end
end"


Forgot an end.
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
23 Jun 2013 06:03 PM
Yes I guess you are right...But for some reason I still like using 'next'.
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
24 Jun 2013 02:28 PM
Sorry to bother you again but how would i use the function PlayerIsAlive(Table, Player) function? Isn't that only possible to do in a local script because player.Character is only available in local script right? ._.
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
24 Jun 2013 02:29 PM
Bump
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
24 Jun 2013 07:48 PM
Bump
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