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

Currency is not Valid Member of Folder?

16:12:44.883 - Points is not a valid member of Folder 16:12:44.884 - Stack Begin 16:12:44.884 - Script 'ServerScriptService.CurrencyScript', Line 31 16:12:44.884 - Stack End*

local replicatedStorage = game:GetService("ReplicatedStorage")
local shopItems = game:GetService("ServerStorage"):WaitForChild("ShopItems")
local currencyName = "Cash"
local DataStore = game:GetService("DataStoreService"):GetDataStore("TestDataStore")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	local currency = Instance.new("IntValue")
	currency.Name = "Cash"
	currency.Parent = leaderstats
	local ID = currencyName.."-"..player.UserId
	local savedData = nil
	
	pcall(function()
		savedData = DataStore:GetAsync(ID)
	end)
		
	if savedData ~= nil then
		currency.Value = savedData
		print("Data Loaded")
	else
		--New Player
		currency.Value = 0
		print("New Player To The Game")
	end
end)

replicatedStorage.GetInfo.OnServerInvoke = function(player,item)
	return shopItems[item].currency.Value
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 game is shutting down")
		end
	end
	
	wait(5)
	
end)

1 comment

0

I see now "Points" at line 31

1 answer

This question has been solved. "currency" on line 31 was suppose to be "cash".

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