Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

i try to remove a tool from a table but the script still counts said tool as a part of the table?

So i have this script inside a tool that contains a numbervalue called "Ammo" the script will destroy the tool once it's value is equals or less than 0. The for i,v script will check if the Ammo's value is equal or less than 0 so that it will remove it from the table.

for i,v Script:

local backpack = plr.Backpack:GetChildren()
				for i,v in ipairs(backpack) do
					if v:WaitForChild("Handle").Ammo.Value <= 0 then
						table.remove(all9mm, v)
					end
					
					if v.Name == "9mm("..v.Handle.Ammo.Value..")" then
						table.insert(all9mm, v) 
					end
				end
				
				local chosenitem = all9mm[math.random(1, #all9mm)]
				
				local function reload()
					ammo.Value = ammo.Value+1
					chosenitem.Handle:FindFirstChild("Ammo").Value = chosenitem.Handle:FindFirstChild("Ammo").Value-1
				end
				
				repeat
					reload()
				until ammo.Value == 15 or chosenitem:FindFirstChild("Handle").Ammo.Value == 0

Destroy tool Script:

local ammo = script.Parent:WaitForChild("Ammo")

ammo.Changed:Connect(function(value)
	if value <= 0 then
		wait(0.5)
		script.Parent.Parent:Destroy()
	end
end)

6 comments

0

Does it give any errors?

0

09:02:13.503 Handle is not a valid member of Tool "9mm(0)" - Server - Script:59

0

Why would you check the handle's name with the ammo value as opposed to only the handle's ammo value?

0

Based on your error message, the script stops because it can't find the handle inside 9mm(0)

0

sorry i meant there was a numbervalue inside of the tool called "Ammo"

0

i also tried disabling the destroy tool script so that the for i,v script can detect the tool, but it still didnt remove the tool for some reason

1 answer

table.remove(table, index) removes the given index, not value; to pull this off you could try: ~~~~~~~~~~~~~~~~~ table.remove(table, table.find(table, value))


1 comment

0

i did but for some reason its still not working

This discussion is preserved as it was. New answers, comments, and votes are closed.