Why is detecting a change in humanoidroot part properties giving me a nil error

  1. i want this script to basically once the humanoidroot part size changes and magnitude “if i could lol” but size and other properties of the root part to kick the player. cause that’s how some ppl are exploiting. just another bypass ppl are using. someone shared me his script he uses to exploit. so i’m trying to find a solution to stop it and he’s oddly trying to help me patch the exploits he’s using lol

  2. some reason i get an error trying to run this code saying “Players.jjphariss.Backpack.Sword.Anti-reach:19: attempt to index nil with ‘HumanoidRootPart’ - Client - Anti-reach:19” i don’t understand how humanoidroot part is nil? it’s just a brick inside the character isn’t it? am i just not understanding it correctly? can someone help me find a solution to this can point me in the right direction or hints clues i don’t mind. i just need some info for why this is even happening and a possible way to fix.

  3. i tried changing the detection and tried changing how it’s locating the humanoid root part. don’t think it matters though since it’s claiming it’s nil anyway.

local parent = script.Parent

local Players = game:GetService("Players")
local plr = Players.LocalPlayer
local char = plr.Character
 

local checker = script.Parent.Handle
local checker2 = checker.Parent.Handle 
local checktool = parent

local humansize = char.HumanoidRootPart








checker2.Changed:Connect(function(check)
	
	if char.HumanoidRootPart.Position or humansize.Size then
		 plr:kick("kicked for trying to reach exploit")
	end
	
	if check == "Size" or checktool.Enabled == false then 
		plr:kick("kicked for trying to reach exploit")
	end
end)

parent.ChildAdded:Connect(function(detect)
	if detect.ClassName == "ScreenGui" or detect.ClassName == "BillboardGui" or detect.ClassName == "Script" or detect.ClassName == "LocalScript" then

		plr:kick("kicked for trying to exploit")
	end
end)

If the player’s character hadn’t loaded before the script ran, then plr.Character doesn’t exist and is thus, nil. You can change this line to this:

local char = plr.Character or plr.CharacterAdded:Wait()

This gets the player’s character if it exists or waits for it if it doesn’t.

oh sh… i didn’t even realize that at all or notice that or knew lmao thank you so much for letting me know specially being so quick on a response.

question. another issue came up. why does it say humanoidrootpart is not a valid member of model? am i not detecting that part correctly? it’s not even allowing to detect the characters head?

In those cases, it’s another problem of the script running before the objects load. To fix those, use WaitForChild:

-- example
local humansize = char:WaitForChild("HumanoidRootPart")

Like Player.CharacterAdded:Wait(), this waits for the provided Instance to load into the game, once it does, it returns the Instance. So, in this example, once HumanoidRootPart is loaded into the game, humansize will be the HumanoidRootPart.

You also, don’t neccessarily need to assign it to a variable. For example, you can do:

if char:WaitForChild("HumanoidRootPart").Position then

i rewrote the code a bit i was gonna share but regardless that fixed the error anyways. thank you so much this worked and i learned. thank you sooo much

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