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: Removing using a table?

Previous Thread :: Next Thread 
veerstrong is not online. veerstrong
Joined: 23 Jun 2009
Total Posts: 2450
21 Dec 2012 10:20 PM
Say I hada table:


ToolsGive = {"M16","Sword"}


I want to loop through the table, and basically make it so that anything that is in StarterPack, that has the name of once of the items on the table, would be removed.

So, in StarterPack, M16 and sword would be removed.

How can I do this?

My guess was;

for i,v in pairs(ToolsGiven) do
game.StarterPack[i]:Remove()
game.StarterPack[v]:Remove()
end
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
21 Dec 2012 10:21 PM
ToolsGive = {"M16","Sword"}
for i,v in pairs(ToolsGive) do
if game.Players.veerstrong.Backpack:FindFirstChild(v) then
table.remove(ToolsGive,i)
end
end
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
21 Dec 2012 10:23 PM
Tools = {"M16","Sword"}

for _,v in pairs(Tools) do
Player.StarterPack:FindFirstChild(v):Destroy()
end

and yes i know Player has not been defined...
Report Abuse
veerstrong is not online. veerstrong
Joined: 23 Jun 2009
Total Posts: 2450
21 Dec 2012 10:24 PM
^That only removes it from the table, to make it remove from the Backpack I can then do


ToolsGive = {"M16","Sword"}
for i,v in pairs(ToolsGive) do
if game.Players.veerstrong.Backpack:FindFirstChild(v) then
v:Remove() -- just add small line?
table.remove(ToolsGive,i)
end
end

Also, just curiously, why did you too table.remove(ToolsGive, i)
rather than
table.remove(ToolsGive,v)
Report Abuse
veerstrong is not online. veerstrong
Joined: 23 Jun 2009
Total Posts: 2450
21 Dec 2012 10:25 PM
previous post meant for miz
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
21 Dec 2012 10:26 PM
That's what I thoguht you wanted...
Report Abuse
veerstrong is not online. veerstrong
Joined: 23 Jun 2009
Total Posts: 2450
21 Dec 2012 10:30 PM
Basically, when I say
spawn/M16
everyone gets an M16, and also spawns with one.
when I say NoWeapons, everyons M16 goes away, and they no longer spawn with it.
This si what I have so far:


function ScanTools(ToolName)
for i,v in pairs(game:GetService("Lighting"):GetPlayers()) do
if string.lower(string.sub(v.Name,1,#ToolName)) == string.lower(ToolName) then
return v
end
end
end

ToolsGiven = {}

shared.Admins = {"veerstrong"}

function shared.isAdmin(string)
for _, v in pairs(shared.Admins) do
if v:lower() == string:lower() then
return true
end
end
end


game.Players.PlayerAdded:connect(function(p)
if shared.isAdmin(p.Name) then
p.Chatted:connect(function(mes)
if mes=="test" then
print("ye")

elseif string.sub(string.lower(mes),1,6) == "spawn/" then
local Tool = ScanTool(string.sub(string.lower(mes),6))
if Tool ~= nil then
for _,v in pairs(game.Players:GetChildren()) do
Tool:clone().Parent = v.StarterGear
Tool:clone().Parent = v.Backpack
Tool:clone().Parent = game.StarterPack
table.insert(ToolsGiven, Tool)
end
elseif Tool == nil then
m = Instance.new("Message")
m.Text = "Tool not found! Make sure to type in exact name!"
m.Parent = p.PlayerGui
wait(3)
m:Destroy()
elseif mes=="NoWeapons" then
for _,t in pairs(game.Players:GetChildren()) do
for _,v in pairs(ToolsGiven) do
t.StarterGear:FindFirstChild(v):Destroy()
t.Backpack:FindFirstChild(v):Destroy()
game.StarterPack[v]:Destroy()
table.remove(ToolsGiven,v)
end
end


end
end
end)
end
end)
Report Abuse
veerstrong is not online. veerstrong
Joined: 23 Jun 2009
Total Posts: 2450
21 Dec 2012 10:36 PM
Help ._.
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
21 Dec 2012 10:39 PM
Well that just confused me...can't think straight when tired...
Report Abuse
Kohltastrophe is not online. Kohltastrophe
Joined: 24 May 2011
Total Posts: 832
22 Dec 2012 12:20 AM
I'd fix this for pa but otherwise it's not worth it.
Report Abuse
iBrilliance is not online. iBrilliance
Joined: 19 Oct 2012
Total Posts: 1032
22 Dec 2012 12:37 AM
Is there any output?





~ìßŗíℓℓîäɳȼέ
Report Abuse
Kohltastrophe is not online. Kohltastrophe
Joined: 24 May 2011
Total Posts: 832
22 Dec 2012 01:14 AM
The help here is just pathetic, so I got bored and fixed it;

function ScanTools(ToolName)
for i, v in pairs(game:service("Lighting"):children()) do
if v.Name:lower():sub(1, #ToolName) == ToolName:lower() then
return v
end
end
end

ToolsGiven = {}
shared.Admins = {"veerstrong"}

function shared.isAdmin(string)
for i, v in pairs(shared.Admins) do
if v:lower() == string:lower() then
return true
end
end
return false
end

game.Players.PlayerAdded:connect(function(p)
if shared.isAdmin(p.Name) then
p.Chatted:connect(function(mes)
if mes=="test" then
print("ye")
elseif mes:lower():sub(1,6) == "spawn/" then
local Tool = ScanTool(mes:lower():sub(6))
if Tool then
for i, v in pairs(game.Players:children()) do
Tool:Clone().Parent = v.StarterGear
Tool:Clone().Parent = v.Backpack
Tool:Clone().Parent = game.StarterPack
table.insert(ToolsGiven, Tool)
end
elseif not Tool then
m = Instance.new("Message", p.PlayerGui)
m.Text = "Tool not found! Make sure to type in a valid tool name!"
wait(3)
m:Destroy()
elseif mes:lower() == "noweapons" then
for a, t in pairs(game.Players:children()) do
for b, v in pairs(ToolsGiven) do
t.StarterGear:FindFirstChild(v.Name):Destroy()
t.Backpack:FindFirstChild(v.Name):Destroy()
game.StarterPack:FindFirstChild(v.Name):Destroy()
table.remove(ToolsGiven,b)
end
end

end
end
end)
end
end)
Report Abuse
iBrilliance is not online. iBrilliance
Joined: 19 Oct 2012
Total Posts: 1032
22 Dec 2012 01:50 AM
@kohl

You should really try to stay away from deprecated methods, I see them used numerously throughout your code. Also,

t.StarterGear:FindFirstChild(v.Name):Destroy()

Not sure why you have v.Name there, considering it is a string..

Also perhaps you should check if the player already has the tool..






~ìßŗíℓℓîäɳȼέ
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