I made a data store to save the player’s Money in the game but oddly it’s not working
Data Store script:
local DataStore = game:GetService("DataStoreService")
local DollarStore = DataStore:GetDataStore("MyDollars")
game.Players.PlayerAdded:Connect(function(plr)
local Dollar = plr:WaitForChild("Dollar")
local data
local succ, err = pcall(function()
data = DollarStore:GetAsync(plr.UserId.."_Dollar", plr.Dollar.Value)
end)
if succ then
Dollar.Value = Dollar
print("Successful")
else
print("Failed")
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local Dollar = plr:WaitForChild("Dollar").Value
local succ, err = pcall(function()
Dollar = DollarStore:GetAsync(plr.UserId.."_Dollar", plr.Dollar.Value)
end)
if succ then
print("Success")
else
print("Failed")
end
end)
And this is the AutoMoney script:
game.Players.PlayerAdded:Connect(function(plr)
local value = Instance.new("NumberValue", plr)
value.Name = "Dollar"
while wait(60) do
value.Value = value.Value + 5
end
end)
Hmm it seems your missing some things, do you have any programming experience if so I could give you a better/more efficient way of making a data store but it may require past knowledge of programming.
If that doesn’t work I can give you some code, but I’d rather you’d learn how to do it instead of just copying and pasting code because you’ll remember it in the past if you do it your self instead of pasting code you don’t understand.
local DataStore = game:GetService("DataStoreService")
local DollarStore = DataStore:GetDataStore("MyDollars")
game.Players.PlayerAdded:Connect(function(plr)
local Dollar = plr:WaitForChild("Dollar")
local data
local succ, err = pcall(function()
data = DollarStore:GetAsync(plr.UserId.."_Dollar")
end)
if succ then
Dollar.Value = data
print("Successful")
else
print("Failed")
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local Dollar = plr:WaitForChild("Dollar").Value
local succ, err = pcall(function()
Dollar = DollarStore:SetAsync(plr.UserId.."_Dollar", plr.Dollar.Value)
end)
if succ then
print("Success")
else
print("Failed")
end
end)