Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

4 comments

0

I don't know what I'm doing wrong

0

What line is the error on?

0

I will have a look

0

09:54:48.733 - Points is not a valid member of Folder (it's not telling me what line it it on)

1 answer

✓ Accepted answer

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.

1 comment

0

Thank you so much

This discussion is preserved as it was. New answers, comments, and votes are closed.