|
| 02 Feb 2013 03:00 PM |
| I need it to Load and Save when entering and leaving game |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 02 Feb 2013 03:02 PM |
| Why thank you I'll check it out |
|
|
| Report Abuse |
|
|
| |
|
|
| 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 |
|
|
| |
|
|
| 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 |
|
|
|
| 02 Feb 2013 03:52 PM |
| Ahhh Thank you,but I don't understand I'm a Rookie Scripter |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 02 Feb 2013 04:16 PM |
| Can you give me the script...? |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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 |
|
|