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 » Scripting Helpers
Home Search
 

Tool Save/Load Script

Previous Thread :: Next Thread 
blackshockwave is not online. blackshockwave
Joined: 16 Mar 2012
Total Posts: 1381
02 Feb 2013 03:00 PM
I need it to Load and Save when entering and leaving game
Report Abuse
Neo1035 is not online. Neo1035
Joined: 25 Jun 2008
Total Posts: 13076
02 Feb 2013 03:00 PM
http://wiki.roblox.com/index.php/Data_persistence_tutorial
Report Abuse
blackshockwave is not online. blackshockwave
Joined: 16 Mar 2012
Total Posts: 1381
02 Feb 2013 03:02 PM
Why thank you I'll check it out
Report Abuse
blackshockwave is not online. blackshockwave
Joined: 16 Mar 2012
Total Posts: 1381
02 Feb 2013 03:04 PM
Don't get it lol
Report Abuse
MeBilly8440 is not online. MeBilly8440
Joined: 27 Jul 2009
Total Posts: 2783
02 Feb 2013 03:09 PM
What's not to get?

player:WaitForDataReady() -- So it works
player:SaveString("OMGERD", "Something you want to save")
print(player:LoadString("OMGERD"))
> Something you want to save

Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson
Report Abuse
blackshockwave is not online. blackshockwave
Joined: 16 Mar 2012
Total Posts: 1381
02 Feb 2013 03:11 PM
...?
Report Abuse
MeBilly8440 is not online. MeBilly8440
Joined: 27 Jul 2009
Total Posts: 2783
02 Feb 2013 03:18 PM
I just explained Data Persistance in a nutshell. From a normal script, you can save values then load them again.

player:WaitForDataReady() -- Wait for their data to be loaded
player:SaveString("wut", "woah") -- Save "woah" to "what"
print( player:LoadString("wut") ) -- Print what "wut" was set to
> woah
(> means the output)

Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson
Report Abuse
blackshockwave is not online. blackshockwave
Joined: 16 Mar 2012
Total Posts: 1381
02 Feb 2013 03:52 PM
Ahhh Thank you,but I don't understand I'm a Rookie Scripter
Report Abuse
MeBilly8440 is not online. MeBilly8440
Joined: 27 Jul 2009
Total Posts: 2783
02 Feb 2013 04:06 PM
I suggest you learn something else first, then.

Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson
Report Abuse
blackshockwave is not online. blackshockwave
Joined: 16 Mar 2012
Total Posts: 1381
02 Feb 2013 04:16 PM
Can you give me the script...?
Report Abuse
MeBilly8440 is not online. MeBilly8440
Joined: 27 Jul 2009
Total Posts: 2783
02 Feb 2013 04:29 PM
No. This forum isn't for requests. Make it yourself.

Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson
Report Abuse
vlekje513 is not online. vlekje513
Joined: 28 Dec 2010
Total Posts: 9057
02 Feb 2013 04:43 PM
--StarterGear Save Script


--Uses data persistance to save your tools between visits.
--Chat "save/" or "load/" to force a save or load
---------------

--What does the player chat to force a save of their tools?
forceSaveCommand = "save/"

--What does the player chat to force a load of their tools?
forceLoadCommand = "load/"

--Clear the current StarterGear when a load is invoked?
clearStarterGearOnLoad = true

--How long does it wait for a player to be data ready?
dataReadyWaitTimeout = 8

--What is told to the player when their stats are saved successfully?
saveSuccessMessage = "Your tools have been saved!"

--What is told to the player when their stats are loaded successfully?
loadSuccessMessage = "Your tools have been loaded!"

--What is told to the player if their stats could not be loaded?
loadErrorMessage = "Your tools could not be loaded. Chat \"" .. forceLoadCommand .. "\" to retry."

--What is told to the player if their stats could not be saved?
saveErrorMessage = "Your tools could not be saved. Chat \"" .. forceSaveCommand .. "\" to retry."


loadFastMessage = "You can only load your tools every 3 minutes."

saveFastMessage = "You can only save your tools every 30 seconds."

--Data persistance prefix for this script (change to clear everyone's saved tools):
dpPrefix = "SavedTools-0-"

--Debug mode
debug = false

save_times = {}
load_times = {}

---------------

debris = game:GetService("Debris")

function tellPlayer(player, text, time)
if not player.Parent then return end
local m = Instance.new("Message", player:findFirstChild("PlayerGui"))
m.Text = text
debris:AddItem(m, time or 3)
end

function waitForDataReady(player)
local start = tick()
while tick() < start + dataReadyWaitTimeout do
if player.DataReady then return true end
wait()
end
return false
end

function playerSave(player)
if not waitForDataReady(player) then tellPlayer(player, saveErrorMessage) return end

if (save_times[player] or 0) + 30 > tick() then tellPlayer(player, saveFastMessage) return end
save_times[player] = tick()

local gear = player:findFirstChild("StarterGear")
if not gear then tellPlayer(player, saveErrorMessage) return end
local tools = gear:GetChildren()
local worked = false
pcall(function ()
player:SaveNumber(dpPrefix .. "Count", #tools)
worked = true
end)
if not worked then tellPlayer(player, saveErrorMessage) return end
for i, tool in pairs(tools) do
pcall(function ()
player:SaveInstance(dpPrefix .. tostring(i), tool)
end)
end
tellPlayer(player, saveSuccessMessage)
end

function playerLoad(player)
if not waitForDataReady(player) then
tellPlayer(player, loadErrorMessage)
return
end

if (load_times[player] or 0) + 60*3 > tick() then tellPlayer(player, loadFastMessage) return end
load_times[player] = tick()

local gear = player:findFirstChild("StarterGear")
local backpack = player:findFirstChild("Backpack")
local current = gear:GetChildren()
local count = 0
pcall(function ()
count = player:LoadNumber(dpPrefix .. "Count")
end)
local tools = {}
for i = 1, count do
pcall(function ()
tools[#tools + 1] = player:LoadInstance(dpPrefix .. tostring(i))
end)
end
for i, tool in pairs(tools) do
local copy = tool:clone()
copy.Parent = backpack
local copy2 = tool:clone()
copy2.Parent = gear
end
if clearStarterGearOnLoad then
for i, tool in pairs(current) do
tool:remove()
end
end
tellPlayer(player, loadSuccessMessage)
end

function onPlayerChatted(player, message, recipient)
message = message:lower()
if message == forceSaveCommand then
playerSave(player)
elseif message == forceLoadCommand then
local s, e = pcall(function ()
playerLoad(player)
end)
if not s then
if debug then tellPlayer(player, "playerLoad error:" .. e) end
end
end
end

function onPlayerEntered(player)
player.Chatted:connect(function (msg, rec) onPlayerChatted(player, msg, rec) end)
playerLoad(player)
end

function onPlayerLeft(player)
local s, e = pcall(function ()
playerSave(player)
end)
if not s then
if debug then Instance.new("Message", workspace).Text = "playerSave error:" .. e end
end
end

game.Players.PlayerAdded:connect(onPlayerEntered)
game.Players.PlayerRemoving:connect(onPlayerLeft)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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