Hi, im making a community system that will use datastores. I need to save them to datastores with unique ID's as keys but i'm not sure about how i can generate an unique number. I've thought about using tick() and math.random but i have no idea if it will be unique in each instance of the game aswell. Please help?
Well, I don't really think you should make it 'random' per say, But I think you should make the ID's a giant list, then save it with a thing called OrderedDataStore: http://wiki.roblox.com/index.php?title=Ordered_data_store
With Ordered data stores you can get the next value up from the last save, I'm not sure how it'd work though. Goodluck m80
Why don't you use the Player's UserId
since that is unique to every user?
As you probably know, math.random() isn't truly random. If you do math.random() in test mode, quit, then do it again, you notice you get the same/very similar numbers. You can reset the seed that math.random() uses by doing math.randomseed(tick()). This will set the seed to how many seconds have passed since January 1st, 1970 (strange, yes, but useful). So, your code would look something like this:
math.randomseed(tick()) getCommunityNumber(math.random())
Maybe you should generate key with random() and then check is this key already in Data Store. If it is then do random() again until you get unique key.