Why is it that Im getting an error even when it is in an if statement?

So I have a scipt that sees if there is a certain item in the player. If its not then it just moves on right?(Cause it is a IF statement)

But it is still giving me an error. Why is this happening?

if not player.Failed then -- this is where the error is.

Could you show us an error please?
We can’t help you without it

  19:45:12.384  Failed is not a valid member of Player "Players.Froyo1002YT"  -  Server - Load/SetupPlayer:84
  19:45:12.384  Stack Begin  -  Studio
  19:45:12.384  Script 'ServerScriptService.Load/SetupPlayer', Line 84 - function saveData  -  Studio - Load/SetupPlayer:84
  19:45:12.384  Script 'ServerScriptService.Load/SetupPlayer', Line 110  -  Studio - Load/SetupPlayer:110
  19:45:12.385  Stack End  -  Studio
  19:45:17.019  Disconnect from ::ffff:127.0.0.1|58129  

What is the error? If statements don’t prevent errors from occurring, they simply check if a condition passes.

Failed isn’t a part of the Player, that’s the problem

Use FindFirstChild to prevent this error.

Oh. I thought that it would not create an error.
How do I fix this?

You’re trying to access a property from the Player that doesn’t exist. If you stored a BoolValue, you need to access its Value property:

if not player.Failed.Value then

If you did not use a BoolValue, what exactly are you looking for?

Oh I think I know how to fix this.

I just need to swap out .Failed for findFirstChild(‘Failed’)

1 Like

Yes, but it would be:

if player:FindFirstChild(“Failed”) == nil then
   return end
elseif player:FindFirstChild(“Failed”) then
--do stuff
1 Like

don’t mark yourself as the solution. only the person who helped you the most in the problem

3 Likes

Oops I clicked on the wrong thing.
Thanks

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