Script saying error is on line 38, but that line doesn't have the code mentioned?

attempt to index nil with ‘Humanoid’ on line 38, but that line is just an end

here’s the script!

--____  U _____ u    _      _   _            _      _   _     _____                ____   _   _  U _____ u    _       _____   
--U | __")u\| ___"|/U  /"\  u | \ |"|       U  /"\  u | \ |"|   |_ " _|     ___    U /"___| |'| |'| \| ___"|/U  /"\  u  |_ " _|  
--\|  _ \/ |  _|"   \/ _ \/ <|  \| |>       \/ _ \/ <|  \| |>    | |      |_"_|   \| | u  /| |_| |\ |  _|"   \/ _ \/     | |    
--| |_) | | |___   / ___ \ U| |\  |u       / ___ \ U| |\  |u   /| |\      | |     | |/__ U|  _  |u | |___   / ___ \    /| |\   
--|____/  |_____| /_/   \_\ |_| \_|       /_/   \_\ |_| \_|   u |_|U    U/| |\u    \____| |_| |_|  |_____| /_/   \_\  u |_|U   
--_|| \\_  <<   >>  \\    >> ||   \\,-.     \\    >> ||   \\,-._// \\_.-,_|___|_,-._// \\  //   \\  <<   >>  \\    >>  _// \\_  
--(__) (__)(__) (__)(__)  (__)(_")  (_/     (__)  (__)(_")  (_/(__) (__)\_)-' '-(_/(__)(__)(_") ("_)(__) (__)(__)  (__)(__) (__)

--Settings
local Warnings = 1
local WarningRange = 7
--WARNING! DO NOT TOUCH THE FOLLOWING CODE. -Korthgreat0
--WARNING! DO NOT TOUCH THE FOLLOWING CODE. -Korthgreat0
--WARNING! DO NOT TOUCH THE FOLLOWING CODE. -Korthgreat0

local runservice = game:GetService("RunService")

game.Players.PlayerAdded:Connect(function(plr)
	local warnings = 0
	repeat
		wait()
	until plr.Character
	local walkspeed = plr.Character.Humanoid.WalkSpeed
	runservice.Heartbeat:Connect(function()
		if plr.Character and plr.Character.PrimaryPart then
			local prevpos = plr.Character.PrimaryPart.Position
			plr.Character.PrimaryPart.Changed:Connect(function(prop)
				if prop == "Position" then
					local magnitude = math.abs((prevpos - plr.Character.PrimaryPart.Position).Magnitude)
					if magnitude >= WarningRange then
						if plr.Character.Humanoid.WalkSpeed <= walkspeed then
							warnings += 1
							if warnings > warnings then
								plr:Kick("Suspected cheating detected.")
							end
						end
					end
				end
			end)
		end
		plr.Character.Humanoid.Died:Connect(function()
			warnings = 0
		end)
	end)
end)

I don’t understand what’s going on, the character clearly exists, and the line the error is at is incorrect!

DO NOT STEAL MY CODE!!!

Cool Code Design


You should Probably wait for the Character as the Player Joins before the Character is Added.

Maybe using:

player.CharacterAdded:Connect(function(character)
-- or:
player.CharacterAdded:Wait()
-- or:
repeat wait() until player.Character

If not, you should check if it prints the Humanoid, or not:

print(plr.Character.Humanoid)
--> Instance or nil?

The error might be on that line but if you look under there will sometimes be some lines of code in blue that lead to the error. I would check those lines as well.

See how in the screenshot my Error is on line 34, but the real problem might be on line 34 or could even be in line 39 of a different script.

there’s already an if statement to check for the character, still getting the error.

those lines say the same thing.

Character does not exist yet, so it is nil, try this.

--____  U _____ u    _      _   _            _      _   _     _____                ____   _   _  U _____ u    _       _____   
--U | __")u\| ___"|/U  /"\  u | \ |"|       U  /"\  u | \ |"|   |_ " _|     ___    U /"___| |'| |'| \| ___"|/U  /"\  u  |_ " _|  
--\|  _ \/ |  _|"   \/ _ \/ <|  \| |>       \/ _ \/ <|  \| |>    | |      |_"_|   \| | u  /| |_| |\ |  _|"   \/ _ \/     | |    
--| |_) | | |___   / ___ \ U| |\  |u       / ___ \ U| |\  |u   /| |\      | |     | |/__ U|  _  |u | |___   / ___ \    /| |\   
--|____/  |_____| /_/   \_\ |_| \_|       /_/   \_\ |_| \_|   u |_|U    U/| |\u    \____| |_| |_|  |_____| /_/   \_\  u |_|U   
--_|| \\_  <<   >>  \\    >> ||   \\,-.     \\    >> ||   \\,-._// \\_.-,_|___|_,-._// \\  //   \\  <<   >>  \\    >>  _// \\_  
--(__) (__)(__) (__)(__)  (__)(_")  (_/     (__)  (__)(_")  (_/(__) (__)\_)-' '-(_/(__)(__)(_") ("_)(__) (__)(__)  (__)(__) (__)

--Settings
local Warnings = 1
local WarningRange = 7
--WARNING! DO NOT TOUCH THE FOLLOWING CODE. -Korthgreat0
--WARNING! DO NOT TOUCH THE FOLLOWING CODE. -Korthgreat0
--WARNING! DO NOT TOUCH THE FOLLOWING CODE. -Korthgreat0

local walkspeed = game:GetService("StarterPlayer").CharacterWalkSpeed
game:GetService("Players").PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(Char)
		local HRP = Char:WaitForChild("HumanoidRootPart")
		local Humanoid = Char:WaitForChild("Humanoid")

		--			Update			--
		local warnings = 0
		local Update = game:GetService("RunService").Heartbeat:Connect(function(dt)
			local prevpos = HRP.Position

			local magnitude = math.abs((prevpos - HRP.Position).Magnitude)
			if magnitude >= WarningRange and Humanoid.WalkSpeed <= walkspeed then
				warnings += dt
				if warnings > Warnings then		plr:Kick("Suspected cheating detected.")		end
			end
		end)
		
		--			Reset			--
		Humanoid.Died:Connect(function()
			Update:Disconnect()
		end)
	end)
end)

Why do I add deltatime (dt) to it? so you really know how many attempts it made per second, if not too fast


Not relevant, but...


:smiling_imp:

Have you checked using Print statements if all nested if/then statements are working?

no error now, but it’s not triggering and kicking me?

Whoops, have to save the previous position.

--____  U _____ u    _      _   _            _      _   _     _____                ____   _   _  U _____ u    _       _____   
--U | __")u\| ___"|/U  /"\  u | \ |"|       U  /"\  u | \ |"|   |_ " _|     ___    U /"___| |'| |'| \| ___"|/U  /"\  u  |_ " _|  
--\|  _ \/ |  _|"   \/ _ \/ <|  \| |>       \/ _ \/ <|  \| |>    | |      |_"_|   \| | u  /| |_| |\ |  _|"   \/ _ \/     | |    
--| |_) | | |___   / ___ \ U| |\  |u       / ___ \ U| |\  |u   /| |\      | |     | |/__ U|  _  |u | |___   / ___ \    /| |\   
--|____/  |_____| /_/   \_\ |_| \_|       /_/   \_\ |_| \_|   u |_|U    U/| |\u    \____| |_| |_|  |_____| /_/   \_\  u |_|U   
--_|| \\_  <<   >>  \\    >> ||   \\,-.     \\    >> ||   \\,-._// \\_.-,_|___|_,-._// \\  //   \\  <<   >>  \\    >>  _// \\_  
--(__) (__)(__) (__)(__)  (__)(_")  (_/     (__)  (__)(_")  (_/(__) (__)\_)-' '-(_/(__)(__)(_") ("_)(__) (__)(__)  (__)(__) (__)

--Settings
local Warnings = 1
local WarningRange = 0.5
--WARNING! DO NOT TOUCH THE FOLLOWING CODE. -Korthgreat0
--WARNING! DO NOT TOUCH THE FOLLOWING CODE. -Korthgreat0
--WARNING! DO NOT TOUCH THE FOLLOWING CODE. -Korthgreat0

game:GetService("Players").PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(Char)
		local HRP = Char:WaitForChild("HumanoidRootPart")

		--			Update			--
		local warnings = 0
		local prevpos = nil
		local Update = game:GetService("RunService").Heartbeat:Connect(function(dt)
			if prevpos then
				local magnitude = math.abs((prevpos - HRP.Position).Magnitude)
				if magnitude >= WarningRange then
					warnings += dt
					if warnings > Warnings then		plr:Kick("Suspected cheating detected.")		end
				end
			end
			prevpos = HRP.Position
		end)

		--			Reset			--
		Char:WaitForChild("Humanoid").Died:Connect(function()
			Update:Disconnect()
		end)
	end)
end)

Also, 7 is too much to be “illegal”, if the player’s speed is 16, with a maximum distance of 0.5 it is fine. And it is not really useful to check the player’s speed, because they usually change the speed locally.

I’m not checking for speed hacks, i’m checking because the game contains speed coils which might false trigger the anticheat.

Alr, then add that restriction again :woman_shrugging:

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