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

Money is not a valid member of folder how to fix??

Asked by 6 years ago

local DataStore = game:GetService("DataStoreService") local ds = DataStore:GetDataStore ("CashSaveSystem")

game.Players.PlayerAdded:connect(function(player) local leader = Instance.new("Folder", player) leader.Name = "leaderstats" local Cash = Instance.new("IntValue", leader) Cash. Name = "Cash" Cash.Value = ds:GetAsync(player.UserId) or 0 Cash.Changed:Connect(function() ds:SetAsync(player.UserId, Cash.Value)

end) 

end)

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

0
You didn't put the code in a code block properly. Can you please fix that to make it easier to read? lunatic5 409 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

The problem is because you added a space between Cash. Name = "Cash". Remove that space. However, you still have a problem! Your SetAsync bit is saving player.leaderstats.Money.Value! You named it Cash! Change it to Cash and it should work.

Final product:

local DataStore = game:GetService("DataStoreService") 
local ds = DataStore:GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:Connect(function(player) 
    local leader = Instance.new("Folder") -- parent argument is deprecated
    leader.Name = "leaderstats" 
    local Cash = Instance.new("IntValue") 
    Cash.Name = "Cash" 
    Cash.Value = ds:GetAsync(player.UserId) or 0
    leader.Parent = player -- assign parent LAST not first
    Cash.Parent = leader

end)

game.Players.PlayerRemoving:Connect(function(player) 
    ds:SetAsync(player.UserId, player.leaderstats.Cash.Value) 
end)

On a side note, remember to paste your code in a code block, like this! It helps us be able to read the code.

0
what do you mean by "CHANGE IT TO CASH"?? ForgottenCollapse -8 — 6y
0
I meant change the name to Cash. User#19524 175 — 6y
Ad

Answer this question