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:
Thanks! (If you need any more info, just let me know)
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”)?