Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Im trying to get my data store script in server script service to work but its not??

Asked by 8 years ago
Edited 8 years ago

Im trying to get my data store script to work but there where 0 errors and it did not work any idea why? It also keeps all stats at 0.

local datastore = game:service("DataStoreService"):GetDataStore("OG-OMDA")

game.Players.PlayerAdded:connect(function(p)
local ls = Instance.new("IntValue", p)
ls.Name = "leaderstats"

local Coins = Instance.new("IntValue", ls)
Coins.Name = "Coins"

local Lvl = Instance.new("IntValue", ls)
Lvl.Name = "Lvl"

local XP = Instance.new("IntValue", ls)
XP.Name = "XP"

local Diamonds = Instance.new("IntValue",ls)
Diamonds.Name = "Diamonds"

            XP.Changed:connect(function()
        Lvl.Value = math.floor(XP.Value / 500)

local k = datastore:GetAsync(p.Name.."key")
if k then
Coins.Value = k[1]
Lvl.Value = k[2]
XP.Value = k[3]
Diamonds.Value = k[4]
else
datastore:SetAsync(p.Name.."key", {Coins.Value,Lvl.Value,XP.Value,Diamonds.Value})
end
end)

game.Players.PlayerRemoving:connect(function(p)
local st = {p.leaderstats.Coins.Value,p.leaderstats.Lvl.Value,p.leaderstats.XP.Value,p.leaderstats.Diamonds.Value}
datastore:SetAsync(p.Name.."key",st)
end)
end)

Please help.

1 answer

Log in to vote
0
Answered by 8 years ago

Why is your script in server storage sir? Put it in ServerScriptService sir

0
it is in serverscriptservice outlook1234567890 115 — 8y
0
sorry typo outlook1234567890 115 — 8y
0
o Spearritt 70 — 8y
Ad

Answer this question