Checking for property errors instead of returning false

I’m running this code simply to check if “SprintSpeed” is a valid property of humanoid and instead of just returning false and continuing it is erroring on the if statement?
image

 if character.Humanoid[stat] then
    character.Humanoid[stat] = NewValue
end

SprintSpeed is not even a valid property of any Humanoid. Are you talking about attributes or children?

You are trying to get a child of humanoid i guess

It’s just how my script works. It loops through values and if the value is a valid property of humanoid.

I am checking the properties not the children, hence why :FindFirstChild isn’t being used here!

But that isn’t a valid property and, you can’t set custom ones.

You can use this function to check if a property is on a provided instance, but like @SomeFedoraGuy said: you cannot assign custom properties to instances.

local function isValidProperty(instance: Instance, name: string): boolean
   local success = pcall(function() -- wrap this in an error catcher to not break the thread
       return instance[name] -- index the property to see if it errors
   end)
   return success -- this will return true if the property was attached to the instance, or false if it errored/not attached to the instance
end
1 Like

I have a similar topic that I posted here: Find property of a guiObject - Help and Feedback / Scripting Support - Developer Forum | Roblox

I ended up just making a dictionary of valid humanoid property names and chekcing that