Scripts:

local data = game:GetService("DataStoreService"):GetDataStore("Hack3214234hg")
game.Players.PlayerAdded:connect(function(plr)
	    local stats = Instance.new("Folder",plr)
	    stats.Name = "leaderstats"
	 
	    local Money = Instance.new("NumberValue",stats)
	    Money.Name = "Money"
	 
	    local SavedItems = data:GetAsync(plr.UserId)
	    if SavedItems then
	        Money.Value = SavedItems.Money or 20
	    else
	        Money.Value = 20
	    end
end)
	 
	script.Parent.MouseButton1Click:connect(function()
	    local price = script.Parent.Parent.Price
	    local player = game.Players.LocalPlayer
	    if game.Players.LocalPlayer.leaderstats.Money.Value >= price.Value then
	        local item = script.Parent.Parent.Item
	        local backpack = player.Backpack
	        local starter = player.StarterGear
	        local clone = game.ReplicatedStorage.Tools:FindFirstChild(item.Value):Clone()
	        local clone2 = game.ReplicatedStorage.Tools:FindFirstChild(item.Value):Clone()
	        clone.Parent = backpack
	        clone2.Parent = starter
	        game.ReplicatedStorage.Buy:FireServer()
	    end
end)
	 
	game.Players.PlayerRemoving:connect(function(plr)
	    local Saving = {["Money"] = plr.leaderstats.Money.Value;
	    }
	    data:SetAsync(plr.UserId,Saving)
end)
 
game.ReplicatedStorage.Buy.OnServerEvent:Connect(function(player)
	player.leaderstats.Money.Value = player.leaderstats.Money.Value - player.Price.Value
end)

It doesnt save the leaderstats if i have it in a local script...

4 comments

0

The client is handling data stores. They can't do that.

0

Make a separate leader stats script as a server script, then make your shop as a local script.

0

Uh it is

0

You refererenced the price in 2 different locations, on line 39 shouldn’t it be price.Value not player.Price.Value?