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...
You need to add one more thing [Look at line 5]
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 game.Players.LocalPlayer.leaderstats.Money.Value - price.Value -- This is what you need to add 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)
I hope that helps you. Good luck.