LuaSlayer
|
  |
| Joined: 09 Jul 2014 |
| Total Posts: 38 |
|
|
| 11 Jul 2014 04:32 PM |
That's right, ALSO TOOLS. Didn't see that? One more time. SAVING ALSO TOOLS!
Q: Is it possible? Nah it isn't. You such lier D: A: Nub. It is, read it below.
Q: Why need DataStore, when you have Data Persistence #SWEG A: Don't #SWEG ME! It is more persistence than Data Persistence. Sometimes, Data Persistence don't load the stats and tools properly. It sometimes don't save and wont give you your last stuff back.
I have been studying nonstop with DevilDefeater. He told me how to use DataStore.
Let's start off with DataStore
saveAs = "Version BETA"
dataStore = game:GetService("DataStoreService"):GetDataStore(saveAs)
Q: Why add the saveAs? Cuz you want to? DOPE A: Change "saveAs" to save it. Return it to default to get old stats back. That's where the data save. DOPE
Okay, let's wait for the player's stats.
saveAs = "Version BETA"
dataStore = game:GetService("DataStoreService"):GetDataStore(saveAs)
game.Players.PlayerRemoving:connect(function(player) player:WaitForDataReady() --To load stuff wait(1) --In case of crash and prevent being homeless end)
Q: Ugh. wait(1). Why is that neccessary? That's so stupid. A: NUB. Do you want your stats to load faster than the player?
Okay, now let's save the player's stats.
saveAs = "Version BETA"
dataStore = game:GetService("DataStoreService"):GetDataStore(saveAs)
game.Players.PlayerRemoving:connect(function(player) player:WaitForDataReady() --To load stuff wait(1) --In case of crash and prevent being homeless stats = player["leaderstats"]:GetChildren() --Change "leaderstats" to your stats for i = 1, #stats do --Creates a loop for every stats dataStore:SetAsync(stats[i].Name, stats[i].Value) end end)
Q: SetAsync? And why save stat's name and value? A: SetAsync, it's like syncing photos to dropbox or google drive. You could save and load from another server/device.
Now that it saves the stats, we need to load the stats when it comes back.
saveAs = "Version BETA"
dataStore = game:GetService("DataStoreService"):GetDataStore(saveAs)
game.Players.PlayerRemoving:connect(function(player) player:WaitForDataReady() --To load stuff wait(1) --In case of crash and prevent being homeless stats = player["leaderstats"]:GetChildren() --Change "leaderstats" to your stats for i = 1, #stats do --Creates a loop for every stats dataStore:SetAsync(stats[i].Name, stats[i].Value) end end)
game.Players.PlayerAdded:connect(function(player) player:WaitForDataReady() --To load stuff wait(1) --In case of crash and prevent being homeless stats = player["leaderstats"]:GetChildren() --Change "leaderstats" to your stats for i = 1, #stats do --Creates a loop for every stats stats[i].Value = dataStore:GetAsync(stats[i].Name) end end)
Q: You did something wrong. Why did you start with (stats[i].Value) instead of dataStore just like at the PlayerRemoving section? And why (:GetAsync(stats[i].Name)) .Name when it wants the .Value? What is GetAsync?
GetAsync, like what I told you, it loads the player stats, like syncing files/pictures/musics/videos/etc. and downloading files from another device. Also, it wants the value back. That's why I started with (stats[i].Value). I used (:GetAsync(stats[i].Name)) instead of .Value because it needs to find the name of the value and load it.
Now I'll give you the full script, due to the messiness ^.
------------------------------------------- saveAs = "Version BETA"
dataStore = game:GetService("DataStoreService"):GetDataStore(saveAs)
game.Players.PlayerRemoving:connect(function(player) player:WaitForDataReady() --To load stuff wait(1) --In case of crash and prevent being homeless stats = player["leaderstats"]:GetChildren() --Change "leaderstats" to your stats for i = 1, #stats do --Creates a loop for every stats dataStore:SetAsync(stats[i].Name, stats[i].Value) end end)
game.Players.PlayerAdded:connect(function(player) player:WaitForDataReady() --To load stuff wait(1) --In case of crash and prevent being homeless stats = player["leaderstats"]:GetChildren() --Change "leaderstats" to your stats for i = 1, #stats do --Creates a loop for every stats stats[i].Value = dataStore:GetAsync(stats[i].Name) end end) -------------------------------------------
Now for the tools. Put all tools in the (game.Lighting.Tools) section, if you don't have one, make a model called "Tools" in (game.Lighting)
WARNING, IGNORE NOW IF YOU DON'T WANNA WASTE YOUR TIME. EDITING GIVER SCRIPTS AND/OR WEAPON DROP SCRIPTS.
Put all the tools in the Tools section.
Ugh I do not wanna explain the steps again.
You get the idea, right?
First, edit ALL the giver/drop script to the tool location to clone. I WARNED YOU.
Here is an example editing:
player = script.Parent.Parent weapon = game.Lighting.Tools["SwordTest"]
while true do wait(0.1) humanoid = player:findFirstChild("Humanoid") if humanoid ~= nil then if humanoid.Health < 1 then wait(1.5) local wep = weapon:clone() wep.Parent = game.Workspace wep.Position = player.Position end end end
I edited the weapon variable.
Add a script to the workspace.
Name it whatever you want.
Put this in:
-------------------------------- saveAs = "Version BETA Tools"
dataStore = game:GetService("DataStoreService"):GetDataStore(saveAs)
function getTools(player) toolsData = player["ToolsUnlocked"] tools = game.Lighting["Tools"] if toolsData["Tool1"].Value == true then toolClone = tools:findFirstChild(toolsData["Tool1"].Value):clone() toolClone.Parent = player.Backpack end if toolsData["Tool2"].Value == true then toolClone = tools:findFirstChild(toolsData["Tool2"].Value):clone() toolClone.Parent = player.Backpack end if toolsData["Tool3"].Value == true then toolClone = tools:findFirstChild(toolsData["Tool3"].Value):clone() toolClone.Parent = player.Backpack end end
game.Players.ChildAdded:connect(function(player) local main = Instance.new("Model") main.Parent = player main.Name = "ToolsUnlocked"
local tool1 = Instance.new("BoolValue") tool1.Parent = main tool1.Name = "NameOfYourTool" tool1.Value = false
local tool2 = Instance.new("BoolValue") tool2.Parent = main tool2.Name = "NameOfYourTool" tool2.Value = false
local tool3 = Instance.new("BoolValue") tool3.Parent = main tool3.Name = "NameOfYourTool" tool3.Value = false
getTools(player) end)
--Change .Value to true if you want them to have the tool for free
game.Players.PlayerAdded:connect(function(player) player:WaitForDataReady() wait(1) tools = player["ToolsUnlocked"]:GetChildren() for i = 1, #tools do tools[i].Value = dataStore:GetAsync(tools[i].Name) end end)
game.Players.PlayerRemoving:connect(function(player) player:WaitForDataReady() wait(1) tools = player["ToolsUnlocked"]:GetChildren() for i = 1, #tools do dataStore:SetAsync(tools[i].Name, tools[i].Value) end end)
Thanks for reading. If I did something wrong, please don't hesitate to post below. PM me if there is a mistake in my scripts. I didn't script this in studio, that's why. I scripted this in this post. |
|
|
| Report Abuse |
|
|
error9999
|
  |
| Joined: 05 Sep 2009 |
| Total Posts: 1593 |
|
|
| 11 Jul 2014 04:37 PM |
this isn't saving the tool right?
it just saved the name of it and a value?
btw, great work c: |
|
|
| Report Abuse |
|
|
LuaSlayer
|
  |
| Joined: 09 Jul 2014 |
| Total Posts: 38 |
|
|
| 11 Jul 2014 04:38 PM |
^ Thanks & Yes, it saves the value, and when the value is set to true, the weapon clones into the player's backpack every time they die, not startgear, cause that will clone too much of it ;P |
|
|
| Report Abuse |
|
|
error9999
|
  |
| Joined: 05 Sep 2009 |
| Total Posts: 1593 |
|
|
| 11 Jul 2014 04:41 PM |
| It's a good way to save tools using DataStore, but I still like Data Pers. more, because it's easier to use and you can use it unlimited times a minute c: |
|
|
| Report Abuse |
|
|
LuaSlayer
|
  |
| Joined: 09 Jul 2014 |
| Total Posts: 38 |
|
|
| 11 Jul 2014 04:42 PM |
| Well, I could also change it to a limited time also. |
|
|
| Report Abuse |
|
|
LuaSlayer
|
  |
| Joined: 09 Jul 2014 |
| Total Posts: 38 |
|
|
| 11 Jul 2014 04:43 PM |
+ This is way better. Some people cannot chat They have to say "/save" or "/load" to save and load the tools. |
|
|
| Report Abuse |
|
|
LuaSlayer
|
  |
| Joined: 09 Jul 2014 |
| Total Posts: 38 |
|
| |
|
error9999
|
  |
| Joined: 05 Sep 2009 |
| Total Posts: 1593 |
|
|
| 11 Jul 2014 04:48 PM |
Data pers doesn't require people to chat
you can just make it save when they leave c: and load it when they enter back
and you could set it for a limited time too c:
like : if player:loadstuff(forgot the name)("limiteditems") == true do well it won't do annything if the player has no limiteditems c:
see, easy :D |
|
|
| Report Abuse |
|
|
LuaSlayer
|
  |
| Joined: 09 Jul 2014 |
| Total Posts: 38 |
|
|
| 11 Jul 2014 05:02 PM |
| Sometimes, when updating the game, the data resets. |
|
|
| Report Abuse |
|
|
error9999
|
  |
| Joined: 05 Sep 2009 |
| Total Posts: 1593 |
|
|
| 11 Jul 2014 05:28 PM |
| well I think roblox fixed that bug |
|
|
| Report Abuse |
|
|
LuaSlayer
|
  |
| Joined: 09 Jul 2014 |
| Total Posts: 38 |
|
|
| 11 Jul 2014 06:21 PM |
| Keep this post up for everyone to learn. |
|
|
| Report Abuse |
|
|
LuaSlayer
|
  |
| Joined: 09 Jul 2014 |
| Total Posts: 38 |
|
| |
|
LuaSlayer
|
  |
| Joined: 09 Jul 2014 |
| Total Posts: 38 |
|
| |
|
|
| 21 Jul 2014 10:10 AM |
| So if I had multiple players, wouldn't they all load the same data? I don't see anything to make the data player specific... |
|
|
| Report Abuse |
|
|
|
| 26 Aug 2014 09:58 PM |
| What about weapon classes? And did you use roblox wiki ? |
|
|
| Report Abuse |
|
|
SentPL
|
  |
| Joined: 25 Jun 2013 |
| Total Posts: 1 |
|
|
| 31 Aug 2014 09:06 AM |
| Do you can just write now a comment with this script without STOPPING because I am confused after all and what do I have to do with it? |
|
|
| Report Abuse |
|
|