--Saving Script
local DSS = game:GetService("DataStoreService")
local datastore = DSS:GetDataStore("GeneralSaveData", "Players")
function generateDataKey(player)
local ret = "uid_" .. player.userId
return ret
end
function generateDataTable(player)
local dataTable = {
Cash = player.leaderstats.Cash.Value
}
return dataTable
end
function saveDataForPlayer(player)
local key = generateDataKey(player)
local data = generateDataTable(player)
datastore:SetAsync(key, data)
end
function inputDataToPlayer(player, data)
player.leaderstats.Cash.Value = data.Cash
end
function loadDataForPlayer(player)
local key = generateDataKey(player)
local data = datastore:GetAsync(key)
inputDataToPlayer(player, data)
end
game.Players.PlayerAdded:connect(function(player)
loadDataForPlayer(player) --Load first thing when they join
player.leaderstats.Cash.Changed:connect(function()
saveDataForPlayer(player) --Save the data when Cash changes value
print("SaveCash")
end)
end)
game.Players.PlayerRemoving:connect(saveDataForPlayer) --Save data when the player leaves the game
This is the New Shop script
local player = game.Players.LocalPlayer
local price = script.Parent.Parent.Price
local tools = game.ReplicatedStorage:WaitForChild("Tools")
local tool = tools:FindFirstChild(script.Parent.Parent.ItemNameValue.Value)
local cash = player.leaderstats:WaitForChild("Cash")
local Purchased1 = script.Parent.Parent.Parent.Frame.Item1.Purchased
local Purchased2 = script.Parent.Parent.Parent.Frame.Item2.Purchased
local Purchased3 = script.Parent.Parent.Parent.Frame.Item3.Purchased
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvents = ReplicatedStorage.RemoteEvents
local Event = RemoteEvents.Buy
Event.OnClientEvent:Connect(function()
if cash.Value < price.Value then
print("NotEnough")
game.ReplicatedStorage.NotEnough:Clone().Parent = player.PlayerGui
wait(3)
player.PlayerGui.NotEnough:Destroy()
end
if cash.Value >= price.Value then
cash.Value = cash.Value - price.Value
if price.Value == 100 then
local oldGun = player.Backpack:FindFirstChildOfClass("Tool") or player.Character:FindFirstChildOfClass("Tool")
oldGun:Destroy()
game.ReplicatedStorage.Tools.Pistol:Clone().Parent = player.Backpack
Purchased1.Value = 1
end
if price.Value == 300 then
local oldGun = player.Backpack:FindFirstChildOfClass("Tool") or player.Character:FindFirstChildOfClass("Tool")
oldGun:Destroy()
game.ReplicatedStorage.Tools.Revolver:Clone().Parent = player.Backpack
Purchased2.Value = 1
end
if price.Value == 500 then
local oldGun = player.Backpack:FindFirstChildOfClass("Tool") or player.Character:FindFirstChildOfClass("Tool")
oldGun:Destroy()
game.ReplicatedStorage.Tools.Uzi:Clone().Parent = player.Backpack
Purchased3.Value = 1
end
end
end)
This is the RemoteEventsScript in serverscriptService
game.Players.PlayerAdded:connect(function(player)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvents = ReplicatedStorage.RemoteEvents
local Event = RemoteEvents.Buy
local Buy = player.PlayerGui:WaitForChild("Gui").Main.Info.Buy
Buy.MouseButton1Click:Connect(function()
Event:FireClient(player)
print("Worked")
end)
end)

2 comments
My bad, i answered that its because you are not loading the value upon joining, but i just didnt see the "View all 41 lines" tab lol i dont usually come on this site. Could it be because your script tries to load and input the data before the intvalue is generated? *edit
he trys to do server stuff with local script