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 » Scripters
Home Search
 

Re: Can anyone please fix this DataStore script for me, please?

Previous Thread :: Next Thread 
EvolutionPower is not online. EvolutionPower
Joined: 16 Dec 2013
Total Posts: 873
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 is not online. 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
EvolutionPower is not online. EvolutionPower
Joined: 16 Dec 2013
Total Posts: 873
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
EvolutionPower is not online. EvolutionPower
Joined: 16 Dec 2013
Total Posts: 873
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 is not online. 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
EvolutionPower is not online. EvolutionPower
Joined: 16 Dec 2013
Total Posts: 873
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 is not online. 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
EvolutionPower is not online. EvolutionPower
Joined: 16 Dec 2013
Total Posts: 873
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 is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
17 Aug 2016 01:23 PM
look at my example to see


Report Abuse
EvolutionPower is not online. EvolutionPower
Joined: 16 Dec 2013
Total Posts: 873
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 is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
17 Aug 2016 01:25 PM
...


Report Abuse
EvolutionPower is not online. EvolutionPower
Joined: 16 Dec 2013
Total Posts: 873
17 Aug 2016 01:26 PM
?



R$37
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
17 Aug 2016 01:27 PM
look at my example to see [2]


Report Abuse
EvolutionPower is not online. EvolutionPower
Joined: 16 Dec 2013
Total Posts: 873
17 Aug 2016 01:29 PM
Ok, i need to name the ServerStorage script 'Modules' and that's it?


R$37
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
17 Aug 2016 01:30 PM
http://prntscr.com/c6z0ko


Report Abuse
EvolutionPower is not online. EvolutionPower
Joined: 16 Dec 2013
Total Posts: 873
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 is not online. 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
CDDevelopment is not online. CDDevelopment
Joined: 16 Mar 2016
Total Posts: 509
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
EvolutionPower is not online. EvolutionPower
Joined: 16 Dec 2013
Total Posts: 873
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
EvolutionPower is not online. EvolutionPower
Joined: 16 Dec 2013
Total Posts: 873
17 Aug 2016 01:40 PM
LAST THING: where do the stats insert into the player?


R$37
Report Abuse
CDDevelopment is not online. CDDevelopment
Joined: 16 Mar 2016
Total Posts: 509
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
LennyFaceDev is not online. LennyFaceDev
Joined: 10 May 2015
Total Posts: 201
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
EvolutionPower is not online. EvolutionPower
Joined: 16 Dec 2013
Total Posts: 873
17 Aug 2016 01:56 PM
dw, its actually legit :)


R$37
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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