Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[SOLVED]How to make a script that runs a math.random , and doesn't run when they rejoin?

Asked by
soutpansa 120
7 years ago
Edited 7 years ago

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!

0
You can check to see if the player already has one of the five of the skills. thePyxi 179 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

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.

0
checking for it wont work, and I'd rather not use data storage this late into the game, sorry. Can someone make an example using data persistence? soutpansa 120 — 7y
0
@soutpansa There's a document on the ROBLOX Wiki for data persistence: http://wiki.roblox.com/index.php?title=Data_persistence_tutorial TheeDeathCaster 2368 — 7y
0
I know how data persistence works xD Forget it, I'll ask a few friends :p soutpansa 120 — 7y
0
I'm just telling you that if you're serious about the game, it should not be using Data persistence. iamnoamesa 674 — 7y
Ad

Answer this question