I've been trying to make a click shop with no gui for a couple hours now which is linked to me leader stats cash value but every time i type the leaderstats name into the separate shop script it says its not a valid member of leaderstats. if someone could help me i would much appreciate it. code pasted below:
local DataStoreService = game:GetService("DataStoreService")
local PlayerCash = DataStoreService:GetDataStore("PlayerCash")
function OnPlayerAdded(player)
local stats = Instance.new("Folder", player)
stats.Name = 'leaderstats'
local Cash = Instance.new("NumberValue", stats)
Cash.Name = "$"
Cash.Value = 0
local data
local success, err = pcall(function()
data = PlayerCash:GetAsync(player.UserId)
end)
if success then
print("Data loaded!")
if data then
Cash.Value = data
end
else
print("There was an error while getting data of player " .. player.Name)
warn(err)
end
while true do
wait(2)
Cash.Value = Cash.Value + 2
end
end
function OnPlayerRemoving(player)
local success, err = pcall(function()
PlayerCash:SetAsync(player.UserId, player.leaderstats:FindFirstChild("$").Value)
end)
if success then
print("Data saved!")
else
print("There was an error while saving data of player " .. player.Name)
warn(err)
end
end
game.Players.PlayerAdded:Connect(OnPlayerAdded)
game.Players.PlayerRemoving:Connect(OnPlayerRemoving)
the shop script below -
local price = 100
script.Parent.MouseClick:Connect(function(player)
if player.leaderstats.PlayerCash.Value >= price then
player.leaderstats.PlayerCash.Value = player.leaderstats.PlayerCash.Value - price
game.ReplicatedStorage.Knife:Clone().Parent = player.backpack
wait(3)
end
end)

2 comments
The name of your value is "$"
what so in the second shop script where i put PlayerCash i would change that to $?