So i have this datasaving leaderboard and shop GUI script, works fine in studio but not in-game. heres the script:
DataStoreService = game:GetService("DataStoreService")
CashDS = DataStoreService:GetDataStore("CashDS")
Event = game.ReplicatedStorage.Minus
local shop = game.Workspace.Shop
local tool = game.ReplicatedStorage:WaitForChild("Tools")
game.Players.PlayerAdded:connect(function(plr)
Shopping = plr.PlayerGui:WaitForChild('Shop')
end)
function FunctionNameHere(player, key)
if player:WaitForChild("leaderstats")["????Cash"].Value >= shop:FindFirstChild("Part" .. Shopping.Item.Value).ItemPrice.Value then
if player.Backpack:FindFirstChild(shop:FindFirstChild("Part" .. Shopping.Item.Value).ItemName.Value) == nil then
if shop:FindFirstChild("Part" .. Shopping.Item.Value) then
local playerKey = key
player:WaitForChild("leaderstats")["????Cash"].Value = player.leaderstats["????Cash"].Value - shop:FindFirstChild("Part" .. Shopping.Item.Value).ItemPrice.Value
wait()
CashDS:SetAsync(playerKey, player.leaderstats["????Cash"].Value)
Shopping.Frame.Buy.Text = "Bought"
Shopping.Frame.Buy.BackgroundColor3 = Color3.new(0.7,0.7,0.7)
Shopping.Frame.Buy.Shadow.BackgroundColor3 = Color3.new(0.5,0.5,0.5)
game.ReplicatedStorage.ShopBuy:FireServer(Shopping.Item.Value)
end
end
end
end
Event.OnServerEvent:Connect(FunctionNameHere)
the datasaving leaderboard script:
local DataStoreService = game:GetService("DataStoreService")
local CashDS = DataStoreService:GetDataStore("CashDS")
game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder",player)
leader.Name = "leaderstats"
local Cash = Instance.new("IntValue",leader)
Cash.Name = "????Cash"
Cash.Value = CashDS:GetAsync(player.Name) or 0
end)
game.Players.PlayerRemoving:connect(function(player)
CashDS:UpdateAsync(player.Name, function(oldValue) return player.leaderstats["????Cash"].Value end)
end)
game.OnClose = function()
for i,v in pairs(game.Players:GetChildren()) do
CashDS:UpdateAsync(v.Name, function(oldValue) return v.leaderstats["????Cash"].Value end)
end
wait(1)
end
Can someone explain to me what the problem is and how to fix it?

3 comments
DataStoreService is inaccessible by client. And using the player's Name to save data is bad, as they can switch usernames and lose their data.
both local scripts or server sided?
never mind already solved.