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

Parent A NameTag In Order To Different Parts?

So I Am Trying To Do Parent Like I Have 3 Parts And I Want Is To That When A Player Touches A Part The Thing Gets Parented To The Next Part In Order (IDk How To Explain maybe the script can tell you)

local cs = {script.Parent.c0, script.Parent.c1, script.Parent.c2} -- these are the parts that i want to be nametags parent when they are touched

local tag = script.Parent.NameTag 

print(cs)

2 comments

0

I DONT WANNA PUT A BILLION SCRIPTS IN EACH PART

0

I DONT WANNA PUT A BILLION SCRIPTS IN EACH PART

1 answer

if you want to keep from duplicating the same script into multiple parts, you can use a for loop to connect to an event for every part in your table

not completely sure if this will work though

local cs = {script.Parent.c0, script.Parent.c1, script.Parent.c2} -- these are the parts that i want to be nametags parent when they are touched

local tag = script.Parent.NameTag 

for i, part in pairs(cs) do
	part.Touched:Connect(function()
		if table.find(cs, part) then -- make sure the part is in the table when it is touched
			tag.Parent = cs[1] -- set the parent to the next value in the table
			table.remove(cs, 1) -- remove the part from the table so that another part will be next
			if #cs == 0 then -- no values left in the table
				cs = {script.Parent.c0, script.Parent.c1, script.Parent.c2} -- reset the table
			end
		end
	end)
end

print(cs)

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