While your issue is specifically with line 8, there's a lot of unneeded code in your script that could be cleaned up. Your issue is that you're checking if the player exists after you're checking for player.Owning
, which means that if anything besides a player touches the head then it will error. This specific issue can be fixed by swapping lines 8 and 9, but a bunch of the code you've written is unneeded.
Another issue with your code (your script will still work if you ignore this) is that you're defining a variable and then basically redefining it two lines later. You're creating a variable for player
, but then you're checking game.Players
for something of the player's name (which will return the player if the player exists). This is like writing x.Parent:FindFirstChild(x.Name)
, it's pointless and you already have the variable you need (in the example, x
). Since you already have a variable for the player, you can shorten line 8 (line 9 with fix) to local Owning = player.Owning
. One more thing with your code that doesn't matter as much: if player ~= nil
is the same thing as writing if player
, no need to compare to nil.