#Datastore

1 messages · Page 1 of 1 (latest)

zenith lotus
#

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local PlayerDataStore = DataStoreService:GetDataStore("PlayerData")

local function loadData(player)
local success, data = pcall(function()
return PlayerDataStore:GetAsync(player.UserId)
end)
if success and typeof(data) == "table" then
return data
else
return {Yellow = true, Pike = false}
end
end

local function saveData(player, data)
pcall(function()
PlayerDataStore:UpdateAsync(player.UserId, function(oldData)
return data
end)
end)
end

Players.PlayerAdded:Connect(function(player)
local data = loadData(player)
local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then
leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
end

local yellowValue = leaderstats:FindFirstChild("Yellow")
if not yellowValue then
    yellowValue = Instance.new("BoolValue")
    yellowValue.Name = "Yellow"
    yellowValue.Parent = leaderstats
end
yellowValue.Value = data.Yellow

local pikeValue = leaderstats:FindFirstChild("Pike")
if not pikeValue then
    pikeValue = Instance.new("BoolValue")
    pikeValue.Name = "Pike"
    pikeValue.Parent = leaderstats
end
pikeValue.Value = data.Pike

end)

local function savePlayer(player)
local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then return end
local data = {
Yellow = leaderstats:FindFirstChild("Yellow") and leaderstats.Yellow.Value or true,
Pike = leaderstats:FindFirstChild("Pike") and leaderstats.Pike.Value or false
}
saveData(player, data)
end

Players.PlayerRemoving:Connect(savePlayer)
game:BindToClose(function()
for _, player in ipairs(Players:GetPlayers()) do
savePlayer(player)
end
task.wait(2)
end)

zenith lotus
#

If I buy the Pike it doesn't save if I exit and come back

odd mantle
#

where you increasing leaderstats

#

which script

zenith lotus
#

equipOrBuyBtn.MouseButton1Click:Connect(function()
if not selected then return end
if selected == "Yellow" then
selectedSaber.Value = "Custom"
equipOrBuyText.Text = "Equipped"
elseif selected == "Pike" then
if ownedSaber.pike then
selectedSaber.Value = "Red Guard Pike Saber"
equipOrBuyText.Text = "Equipped"
else
local px = tonumber(pikeBtn:WaitForChild("Prize").Text)
if credits.Value >= px then
credits.Value -= px
ownedSaber.pike = true
local pikeValue = ownedSaberFolder:FindFirstChild("Pike")
if pikeValue then
pikeValue.Value = true
end
creditsText.Text = credits.Value
selectedSaber.Value = "Red Guard Pike Saber"
equipOrBuyText.Text = "Equipped"
else
print("Insufficent credits")
end
end
end
end)

odd mantle
#

whatever you add it

#

that yyou bought it

zenith lotus
#

?

odd mantle
#

tell me where you change it

zenith lotus
#

The Pike is not saving

odd mantle
#

WHICH SCRIPT

#

tells your game

#

that its bought or not

zenith lotus
#

If I buy, the script change pike.Value to true

odd mantle
#

localscript or serverscript

zenith lotus
#

local

odd mantle
#

learn diffrence

#

between server and local

#

if you change anything locally, server doesnt see it

#

so it might aswell not exist

#

in your case

#

so your datasaving script doesnt see it

zenith lotus
#

can u help me to fix it?

odd mantle
#

and all giving

zenith lotus
#

coin calculation?

odd mantle
#

should be on server

#

thats regarding currency

#

and stuff

zenith lotus
#

So the problem is the local or the script?

odd mantle
#

in local

#

thats regarding data

#

aka dont change leaderstats

#

cuz server wont see it

zenith lotus
hardy fern
#

i think

#

this stores data

zenith lotus
hardy fern
#

i dunno can i

#

ğğğğğğğğğğğğ

summer solar
#

its reliable and easy to learn when you dont understand at all how data storing and things to secure it work

hardy fern
#

well this guy knows

#

as u can seee

#

hes smart

#

im not

summer solar
summer solar
zenith lotus
summer solar
#

and read from there

zenith lotus
#

.

#

I added the modulescript

#

But I dont know how to use it