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

why does this only work with 1 tool? [unanswered]

script.Parent.ChildAdded:connect(function(g)
	wait(0.5)
	local newtool = g
	local oldtools = game.Lighting:GetChildren()
	for i,v in pairs(oldtools)do
		local oldname = v.Name
		if newtool.Name ~= oldname then
			newtool:Destroy()
		end
	end
end)

so basically i want this script to delete any tool that is added in players backpack if it does not have the same name as 1 of the tools in lighting. but this script only deletes the tool if there is 1 tool in lighting if there are 2 or more tools in lighting this script will not destroy the tool that is added to the backpack. please help

1 comment

0

Pls use server storage not lighing to store models.

1 answer

Your script should work like this:

script.Parent.ChildAdded:connect(function(g)
	if not game:service'Lighting':FindFirstChild(g.Name,true) then
		g:Destroy() 
		--put code logging the deletion here
	end;
end)

Ideally, you should store all tools in ServerStorage to prevent them being exploited into a Player's backpack, however LocalScripts cannot access this Service or any of its Descendant Instances.

2 comments

0

ok i will use server storage from now on

0

i am not fully english so please can you explain what you mean by 'put code logging the deletion here'

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