|
| 17 Aug 2016 12:38 PM |
There are 2 scripts, the first one is when they enter and the second is them leaving. The stats are ment to save when they leave and load when they enter but nothing wrong is in the Output. First Script: local DataStore = game:GetService("DataStoreService"):GetDataStore("EvolutionPowerIsBoss")
game.Players.PlayerAdded:connect(function(player) local stats = Instance.new("IntValue", player) stats.Name = "leaderstats" local level = Instance.new("IntValue", stats) level.Name = "Level"
local coins = Instance.new("IntValue", stats) coins.Name = "PokeCoins"
local exp = Instance.new("IntValue", stats) exp.Name = "XP"
local key = "player-"..player.userId
local savedValues = DataStore:GetAsync(key)
if savedValues then level.Value = savedValues[1] coins.Value = savedValues[2] exp.Value = savedValues[3] else local valuesToSave = {level.Value, coins.Value, exp.Value} DataStore:SetAsync(key, valuesToSave) end
end)
Second Script: local DataStore = game:GetService("DataStoreService"):GetDataStore("EvolutionPowerIsBoss")
game.Players.PlayerRemoving:connect(function(player) local key = "player-"..player.userId local valuesToSave = {player.leaderstats.level.Value, player.leaderstats.coins.Value, player.leaderstats.exp.Value} DataStore:SetAsync(key, valuesToSave) DataStore:UpdateAsync(key, function(oldValue) return valuesToSave end) end)
R$37 |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 17 Aug 2016 12:39 PM |
like i said, follow this format
https://forum.roblox.com/Forum/ShowPost.aspx?PostID=195621950
|
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 12:40 PM |
I don't understand what to edit in your script :/, please can u tell me?
R$37 |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 12:44 PM |
I'll pay u 20 robux if u can turn all my values into your script :(
R$37 |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 17 Aug 2016 12:46 PM |
There you go.
local DataHandler = require(game.ServerStorage.Modules:WaitForChild('DataHandler'))
game.Players.PlayerAdded:connect(function(player) DataHandler.LoadData(player) end)
game.Players.PlayerRemoving:connect(function(player) DataHandler.SaveData(player) end)
--module
local PlayerData = game:GetService('DataStoreService'):GetDataStore('PlayerData')
local PlayerStats = { Stats = { Level = 0, PokeCoins = 0, XP = 0, }, }
local DataHandler = {}
LoadStats = function(Player) for i,v in next, PlayerStats do local Stats = Instance.new('Folder',Player) Stats.Name = i for key,val in next, v do local Int = Instance.new('IntValue',Stats) Int.Name = key Int.Value = val end end end
SaveStats = function(Player) local Stats = Player:WaitForChild('Stats') for i,v in next, Stats:GetChildren() do PlayerStats[Stats.Name][v.Name] = v.Value end end
DataHandler.LoadData = function(Player) local UserId = Player.UserId local Data = PlayerData:GetAsync(UserId) if Data then PlayerStats = Data else PlayerData:SetAsync(UserId,PlayerStats) end LoadStats(Player) end
DataHandler.SaveData = function(Player) local UserId = Player.UserId SaveStats(Player) PlayerData:SetAsync(UserId,PlayerStats) end
return DataHandler
|
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 12:47 PM |
Okay so it's 1 script but should it be local or just normal and do i have to do a module folder in serverstorage?
R$37 |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 17 Aug 2016 12:49 PM |
server script goes into serverscriptservice
module goes into srverstorage
|
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 01:18 PM |
do i have to name the scripts to anything..eg: the serverstorage one to Modules?
R$37 |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
| |
|
|
| 17 Aug 2016 01:24 PM |
I was ment to make them just scripts as well right? Not module or local.
R$37 |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
| |
|
| |
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 17 Aug 2016 01:27 PM |
look at my example to see [2]
|
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 01:29 PM |
Ok, i need to name the ServerStorage script 'Modules' and that's it?
R$37 |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
| |
|
|
| 17 Aug 2016 01:31 PM |
SO i don't need modules? Just need to rename the serverscriptservice script 'DataHandler'
R$37 |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 17 Aug 2016 01:34 PM |
OMFG. IF YOU LOOKED IN MY CODE YOU WOULD CLEARLY SEE
(--server)
(--module)
THAT MEANS FIRST PORTION GOES IN A SERVER SCRIPT IN SERVERSCRIPTSERVICE SECONDPORTION GOES INTO A MODULESCRIPT CALLED DATAHANDER INSIDE A FOLDER CALLED MODULES
IS THAT CLEAR ENOUGH FOR YOU???? FFS
|
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 01:37 PM |
First off, I seem to remember quite recently getasync has a limit of uses in a minute. Although don't quote me on that because i'm not 100% sure.
What I do know is this is over complicated by a massive amount. The system I use is very simple and can be used on filtering enabled as well.
for filteringenabled: First if you want to save from a localscript, you can use a remote event and pass certain arguments to connect a function from a server script.
LocalScript;
game.ReplicatedStorage.RemoteEvent:FireServer(Data Name,"String" or "Number",What is saved)
ServerScript;
game.ReplicatedStorage.RemoteEvent.OnServerEvent:connect(function(Player,Data,Type,Save) if Type == "String" and Player.DataReady then Player:SaveString(Data,Save) elseif Type == "Number" and Player.DataReady then Player:SaveNumber(Data,Save) end end)
to load the data from a localscript you can use a similar sytle with a remote function
LocalScript; local load = game.ReplicatedStorage.Load:InvokeServer(Data,"String" or "Number",Player)
ServerScript;
local loaddata = game.ReplicatedStorage.RemoteFunction
function loaddata.OnServerInvoke(Plyr,Data,Type,Player) if Type == "String" then return Player:LoadString(Data) elseif Type == "Number" then return Player:LoadNumber(Data) end print ("Loaded "..Type.." "..Data.." for "..Player.Name) end
^The reason player is passed twice is so the last can be substituted by a player that isn't the LocalPlayer
if you're not using filtering enable you can either do the same passes from local to server via _G.Function = function() or you can just manage it all on ServerScripts via :LoadString and :LoadNumber. |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 01:37 PM |
chill pls man...im a beginner scripter and i don't get complex stuff yet but the script in serverscriptservice need a name?
R$37 |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 01:40 PM |
LAST THING: where do the stats insert into the player?
R$37 |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 01:43 PM |
| Wow, you really are a simplistic scripter. I don't think using physical values within the player is a very secure system. It also essentially puts a "BAD GAME" label on your game rather instantly; much in the same way using tools does to a shooter game. |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 01:54 PM |
PokeCoins...? please don't tell me this is for another awful ROBLOX Clickbait Pokemon Go Simulator Game.. :/
#GlazedDonuts
|
|
|
| Report Abuse |
|
|
|
| 17 Aug 2016 01:56 PM |
dw, its actually legit :)
R$37 |
|
|
| Report Abuse |
|
|