I was wondering if anyone had any idea on how I would be able to accomplish this. I thought of looping through the parts and changing their names but that interferes with scripts that rely on parts being named certain things. I also thought of adding a string value to the parts but that creates lots of instances. Anyone know of any better ways to give each part a unique id?
You should use collection service.
It doesn’t create any new instances within parts, and can be accessed anywhere by any script.
Essentially, you can create new IDs and assign instances to them.
And since it’s a service, it runs on C code, which is faster than making your own Lua algorithm.
Adding on to what @UltimateRaheem said, you can use CollectionService and if every single part has to be a different id, you can use math.random(1,100000). The chance exists that the same number will come up twice, but the chances are very very slim
@benben3963, you could try this approach and then check if that ID doesn’t exist anymore.
There are also other ways to make random IDs.
EDIT
There is a randomseed function that roblox uses. I don’t know much about it… but you should investigate it.
There is a function called HttpService called GenerateGUID, so that is a possible option.
Yah, was wondering about that. I just can’t tell if it has any rate limiting on it like other HttpService functions.
It has no rate limits iirc, only Get/Post/RequestAsync have those limits.
You are correct. Even if the function did have a rate limit, there shouldn’t really be a reason why you’re hitting it - there’s no reason to use GUIDs that much.
local HttpService = game:GetService("HttpService")
for i = 1, 10000 do
print(HttpService:GenerateGUID())
end
Printed all as expected without any warnings or errors.
If you only need each part to have a per- server- unique ID, you don’t need to bother with GUIDs or random generation, you can just start at 1 and increment it for each part, so the serial numbers are 1 for first part, 2 for second part, 3 for third, etc.