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

I am having a error saying (Not a valid member)?

Asked by 4 years ago

I am having some trouble with this script (by the way I didn't do this script I copyed it from a youtuber called (AlvinBlox) when ever I launch the game and I look at the output it pops up with Points is not a valid member of folder

Here is the script (it is a currency script that also saves your data)

local CurrencyName = "Points" -- Here is the currencys name
local DataStore = game:GetService("DataStoreService"):GetDataStore("DataSaver")

game.Players.PlayerAdded:Connect(function(player) -- When a player is added to Players
    local folder = Instance.new("Folder") -- Putting a folder into the player that joined Players
    folder.Name = "leaderstats" -- Folders name
    folder.Parent = player -- The folders parent = player

    local currency = Instance.new("IntValue") -- currency that has a IntValue to it
    currency.Name = CurrencyName -- The name of the currency(its at the top of the script)
    currency.Parent = folder -- The currencys parent =folder

    local ID = CurrencyName.."-"..player.UserId -- players Id
    local savedData = nil

    pcall(function()
        savedData = DataStore:GetAsync(ID)
    end)

    if savedData ~= nil then
        currency.Value = savedData
        print("Data Loaded!")
    else
        -- New Player Currency Only
        currency.Value = 50
        print("New Player To The Game")
    end


end)

game.Players.PlayerRemoving:Connect(function(player)
    local ID = CurrencyName.."-"..player.UserId
    DataStore:SetAsync(ID,player.leaderstats(CurrencyName).Value)
end)

game:BindToClose(function()

    -- When Game Is Ready To ShutDown

    for i, player in pairs(game.Players:GetPlayers()) do
        if player then
            player:Kick("This server is shutting down")
        end
    end

    wait(5)

end)

If anyone could help me that would be great (Its a normal script not a local, the script is in ServerScriptService)

0
I don't know what I'm doing wrong xxoplol47811t 34 — 4y
0
What line is the error on? Reset8449879 204 — 4y
0
I will have a look xxoplol47811t 34 — 4y
0
09:54:48.733 - Points is not a valid member of Folder (it's not telling me what line it it on) xxoplol47811t 34 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Change line 34 from:

DataStore:SetAsync(ID,player.leaderstats(CurrencyName).Value)

to:

DataStore:SetAsync(ID,player.leaderstats[CurrencyName].Value)

You were using parentheses which are used for function calls. Replacing these with brackets will fix the issue, as these are used for indexing.

0
Thank you so much xxoplol47811t 34 — 4y
Ad

Answer this question