How to get all the names of folders inside a folder and also make the names 1 variable?

So once again I have found myself in a pickle. This time, i need to get all the names of folders inside a folder and also make the names 1 variable. However, what i have tried has not worked, and gives me an error: “Players.Noobzilla1207.PlayerScripts.MainClient:80: attempt to index nil with ‘Damage’.” (And yes, i do have the damage value in the pets). Any help would be appreciated!

Here is the script I have made:

	task.spawn(function()
		while wait(1) do
			if valuesFolder.SentTo.Value ~= nil then
				local PPs = workspace.MainFolder_Workspace.PlayerPets
				local CPPs = PPs[player.Name]
				local pet = CPPs.:FindFirstChildOfClass("Model")
				local dmg = pet.Damage.Value
				valuesFolder.SentTo.Value.Health.Value = math.max(valuesFolder.SentTo.Value.Health.Value - dmg, 0)
				if valuesFolder.SentTo.Value.Health.Value == 0 then
					remotes.StopDamaging:FireServer()
					destroyDrop(valuesFolder.SentTo.Value)
				end
			end
		end
	end)
end)

Screenshot of the folders:
idk

Thanks! (If you need any more info, just let me know)

2 Likes

From the error that you have provided, it looks like your code is not actually setting the variable “pet” to anything. This may be the cause of the problem, since you are trying to get values from something that does not exist. While looking at this line of code:

local pet = CPPs.:FindFirstChildOfClass("Model")

There may be a typo, since there is a period and a colon together. I would presume that you mean to type :FindFirstChildOfClass(“Model”) instead of .:FindFirstChildOfClass(“Model”)?

yes, but i have removed the period and it still does not work (gives the same error)

Do you think that it would help to output each variable as it sets it, so that we can see where the code is going wrong?

(Also, could you please tell us exactly which line of code is erroring?)

this is the line that is erroring:

local dmg = pet.Damage.Value

could it be because its getting the folder “BasicEgg” instead of the pets? (i could show you some of the earlier script)

Could you try to print out the variable “pet”?
The error could happen if “pet” is nil.

wait i think i know the issue. i havent actually put the pets into the CPPs folder :sweat_smile:

Try putting some pets in there, maybe it will work then! :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.