Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

<Solved> Why doesn't this work?

Asked by 4 years ago
Edited 4 years ago

Never mind i fixed it

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("Money")

game.Players.PlayerAdded:Connect(function(Player)
    local Leaderstats = Instance.new("Folder")
    Leaderstats.Name = "leaderstats"
    Leaderstats.Parent = Player
    local Currency = Instance.new("StringValue")
    Currency.Name = "Money"
    Currency.Value = DataStore:GetAsync(Player.UserId) or 0
    Currency.Parent = Leaderstats
end)

game.Players.PlayerRemoving:Connect(function(Player)
    DataStore:SetAsync(Player.UserId, Player.leaderstats.Money.Value)
end)

Here is the good script

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("MoneyStats") -- Change this with a random name.

game.Players.PlayerAdded:Connect(function(Player)
    local Leaderstats = Instance.new("Folder")
    Leaderstats.Name = "leaderstats"
    Leaderstats.Parent = Player
    local Currency = Instance.new("StringValue")
    Currency.Name = "Money" -- Change this with your currency name.
    Currency.Value = DataStore:GetAsync(Player.UserId) or "0"
    Currency.Parent = Leaderstats
end)

game.Players.PlayerRemoving:Connect(function(Player)
    DataStore:SetAsync(Player.UserId, Player.leaderstats.Money.Value)
end)

Answer this question