|
Can someone explain how they work?
I got a script for it, but maybe the Value of "stat" should be my value.
[This isn't my script, I'm just trying to figure out Data stores for my "Gold" leadboard, it won't save between servers no mater how I edit it]
game.Players.PlayerRemoving:connect(function(player)
local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")
local statstorage = player:FindFirstChild("leaderstats"):GetChildren()
for i = 1, #statstorage do
datastore:SetAsync(statstorage[i].Name, statstorage[i].Value)
print("saved data number "..i)
end
print("Stats successfully saved")
end)
--[[
Loadin'
Dem
Stats
--]]
game.Players.PlayerAdded:connect(function(player)
local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")
player:WaitForChild("leaderstats")
wait(1)
local stats = player:FindFirstChild("leaderstats"):GetChildren()
for i = 1, #stats do
stats[i].Value = datastore:GetAsync(stats[i].Name)
print("stat numba "..i.." has been found")
end
end) |
|
|
|
@a=war, I don't understand how the scripts work, and where you insert them, I tried the wiki but there was to much details, I couldn't understand it |
|
|
This script doesn't work. I tried it. |
|
|
Actually, I just so happen to still have the script from when I started learning about DataStore myself. The following code is a leaderboard that saves a player's Gold using DataStore. This allows the information to read later without needing the player being checked to be online. This means you could enter the game and view the Gold for anyone who had ever played the game.
CashStore = game:GetService("DataStoreService"):GetDataStore("DataStore")
function PlayerEntered(player)
repeat wait() until player.Character
local stats = Instance.new("IntValue")
stats.Parent = player
stats.Name = "leaderstats"
local cash = Instance.new("IntValue")
cash.Parent = stats
cash.Name = "Cash"
if CashStore:GetAsync("Points_"..player.Name) ~= nil then
cash.Value = CashStore:GetAsync("Points_"..player.Name)
else
cash.Value = 0
CashStore:SetAsync("Points_"..player.Name, Val)
end
cash.Changed:connect(function(Val)
CashStore:SetAsync("Points_"..player.Name, Val)
end)
end
game.Players.PlayerAdded:connect(PlayerEntered) |
|
|
I suppose I could also shorten/compact it a bit as well.
CashStore = game:GetService("DataStoreService"):GetDataStore("DataStore")
function PlayerEntered(player)
repeat wait() until player.Character
stats = Instance.new("IntValue",player)
stats.Name = "leaderstats"
cash = Instance.new("IntValue",stats)
cash.Name = "Cash"
if CashStore:GetAsync("Points_"..player.Name) ~= nil then
cash.Value = CashStore:GetAsync("Points_"..player.Name)
else
cash.Value = 0
CashStore:SetAsync("Points_"..player.Name, Val)
end
cash.Changed:connect(function(Val)
CashStore:SetAsync("Points_"..player.Name, Val)
end)
end
game.Players.PlayerAdded:connect(PlayerEntered) |
|
|
CashStore = game:GetService("DataStoreService"):GetDataStore("DataStore");Spawn(wait)
function PIayerEntered(pIayer)
repeat wait() untiI player.Character
stats = Instance.new("IntValue",player)
stats.Name = "Ieaderstats"
cash = lnstance.new("IntValue",stats)
cash.Name = "Cash"
if CashStore:GetAsync("Points_"..player.Name) ~= niI then
cash.Value = CashStore:GetAsync("Points_"..pIayer.Name)
else
cash.Value = 0
CashStore:SetAsync("Points_"..pIayer.Name, VaI)
end
cash.Changed:connect(function(Val)
CashStore:SetAsync("Points_"..pIayer.Name, Val)
end)
end
game.PIayers.PlayerAdded:connect(PlayerEntered) |
|
|
Could you not post useless replies? The code I gave works perfect. |
|
|
@Counter, it actually doesn't work at all. |
|
|
I'm guessing your trying to run it in "Solo" mode rather than "Play" mode. You can't access DataStore without being in a server. |
|
|
I'm not dumb. It doesn't work. |
|
|
Are you sure about that? I just setup a clean place to double check.
http://www.roblox.com/Lua-place?id=52614695 |
|
|
I don't understand why it's not working for my servers, it's getting quiet annoying |
|
|
umg hi trail im karmavore |
|
|
Hey Karm, you looking for help to? Or are you here helping? |
|
|
i love when newbies (counter) give bad advice |
|
|
A little bit of both trail :3 |
|
|
Can you help with this? qq
I need data to transfer over, but it always has trouble |
|
|
scripting isnt for everyone |
|
|
I agree @both
I tried learning it, I only understood through the wiki, math values
Through editing scripts I understand a bit of functions, but not how to create them |
|
|
Figured out the issue finally, I had another script blocking it from working :\ |
|
wish_zJoin Date: 2009-02-11 Post Count: 15392 |
Do not use the player's name, use their userId instead. It's better. If they change their name, they lose all the data. |
|