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

How to add a number to an Instance to prevent a naming collision?

I have this script so far:

local instance = Instance.new("Part", game.Workspace)

for i,v in ipairs(game.Workspace:GetChildren()) do
	if v:IsA("Part") then
				
	end		
end

But I get stuck at this point because I can't figure out how to do check if a part with that name exists without hardcoding a loop each and every time

1 answer

You shouldn’t use if v:IsA("Part"), use if v:IsA("BasePart").

local instance = Instance.new("Part") 
instance.Parent = game.Workspace

for _, v in pairs(game.Workspace:GetChildren()) do
    if v:IsA"BasePart" then 
    -- if you used Part instead of basepart you’d get seats and spawnlocations only. 
        if v.Name == 'NAMEHERE' then -- in between '' put the name
            -- do code
        end
    end
end

1 comment

0

But I don't know how to create a loop to check if the name is already there because how would the script know that there isn't another part with that name that I changed the name to? Thats the part im stuck in

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