I'm currently developing a game where I want to add a random skill feature. When the player joins for the first time (or first time after the script(s) is added) I want a math.random function to pick a number from 1-5, to set on a value called RandomMove. I have the RandomMove IntValue made already from DataPersistance. Please help?
P.S Happy 2017!
You shouldn't be using DataPersistance. Simply use Datastores to save your data, and if the Value isn't there to load, it randomizes one. Example:
local DataStore = game:GetService("DataStoreService"):GetDataStore("PlayerStat") -- This is like a folder game.Players.PlayerAdded:connect(function(plr) --once they join local Data = ("Data" .. plr.UserId) local DataTable = DataStore:GetAsync(Data) or {math.randomseed(1,5),0,0,0} --and the other data that needs to be saved local Data = Instance.new('IntValue', plr) -- this isn't shown to other players, not leaderstats Data.Name = 'Data' local random = Instance.new('IntValue', Data) random.Name = 'RandomMove' random.Value = DataTable[1] or math.random(1,5) --other saves end)
This is just a bad example I quickly made, it probably even has mistakes. You'd still need to add the end of the script that saves it once they leave, but I'm not going to take that much time making you an actual script. This is just to help you understand how Datastores look like, so please research them and you'll find that easy.