generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Random... not so random?

Previous Thread :: Next Thread 
Creativede is not online. Creativede
Joined: 17 Aug 2008
Total Posts: 683
23 Jul 2014 01:03 AM
This script is giving every user the exact same serial number every time. I've changed the name of the DataStore several times already, and it gives one person a random serial then everyone else has the same serial as that first person.

local DataStore = game:GetService("DataStoreService"):GetDataStore("UserSerials")
local Utils = assert(LoadLibrary("RbxUtility"))
blank ={}
function script.Parent.OnServerInvoke(playername)
pastSN = DataStore:GetAsync("usr_"..playername.Name) or "blank"
print(pastSN)
if pastSN == "blank" then
letters = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}
first = math.random(1,9)
second = letters[math.random(#letters)]
third = math.random(1,9)
fourth = math.random(1,9)
fifth = letters[math.random(#letters)]
sixth = math.random(1,9)
seventh = letters[math.random(#letters)]
eighth = math.random(1,9)
ninth = math.random(1,9)
tenth = letters[math.random(#letters)]
SN = "SN_"..first..second..third..fourth..fifth..sixth..seventh..eighth..ninth..tenth..""
print(SN)
--[[DataStore:UpdateAsync("base", function(oldValue)
local newValue = oldValue or Utils.EncodeJSON(blank) --oldValue might be nil
newValue = Utils.DecodeJSON(newValue)
table.insert(newValue,SN)
table.insert(newValue,player)
newValue = Utils.EncodeJSON(newValue)
return newValue
end)]]--
DataStore:SetAsync("usr_"..playername.Name,SN)
return SN
else
return pastSN
end
end
Report Abuse
FertileTurtle is not online. FertileTurtle
Joined: 04 Dec 2012
Total Posts: 1414
23 Jul 2014 01:04 AM
Put this at the top

math.randomseed(tick())
Report Abuse
Creativede is not online. Creativede
Joined: 17 Aug 2008
Total Posts: 683
23 Jul 2014 01:08 AM
That fixed it, thanks!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image