Attempt to index nil with 'GetDescendants'

	while true do
		wait(0.5)
		local char = plr.Character or plr.CharacterAdded:Wait()
		if char then
			if plr.Character:FindFirstChild("Handcuffs") then
				for i,v in pairs(game.Players:GetChildren()) do
					if v ~= plr then
						if v.Character then
							for o,p in pairs(v.Character:GetDescendants()) do -- this is line 14
								if p:IsA("ProximityPrompt") and p.Name == "Arrest" then
									p.Enabled = true
								end
							end
						end
						
					end
				end


I fixed this bug but it happens again

2 Likes

Does this happen consistently or only randomly?

randomly. It seems to me that this happens when players leave the game (I’m not sure)

if v.Character then
						local char = v.Character
						for o, p in pairs(char:GetDescendants()) do -- this is line 14
							if p:IsA("ProximityPrompt") and p.Name == "Arrest" then
								p.Enabled = true
							end
						end
					end

Can you share the full script? It seems that this is incomplete.

local plr = game.Players.LocalPlayer
local PickDebounce = false
local ArrestDebounce = false

coroutine.wrap(function()
	while wait(0.5) do
		local char = plr.Character or plr.CharacterAdded:Wait()
		if char then
			if plr.Character:FindFirstChild("Handcuffs") then
				for i,v in pairs(game.Players:GetChildren()) do
					if v ~= plr then
						if v.Character then
							for o,p in pairs(v.Character:GetDescendants()) do
								if p:IsA("ProximityPrompt") and p.Name == "Arrest" then
									p.Enabled = true
								end
							end
						end
						
					end
				end
			else
				for i,v in pairs(game.Players:GetChildren()) do
					if v.Character then
						if v ~= plr then

							for o,p in pairs(v.Character:GetDescendants()) do
								if p:IsA("ProximityPrompt") and p.Name == "Arrest" then
									p.Enabled = false
								end
							end
						end
					end
					
				end
			end
		end
	end
end)()
local players = game:GetService("Players")
local plr = players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local PickDebounce = false
local ArrestDebounce = false

coroutine.wrap(function()
	while task.wait(0.5) do
		if plr and char then
			if char:FindFirstChild("Handcuffs") then
				for _, player in pairs(players:GetPlayers()) do
					if player ~= plr then
						if player.Character then
							local character = player.Character
							for _, prompt in pairs(character:GetDescendants()) do
								if prompt:IsA("ProximityPrompt") and prompt.Name == "Arrest" then
									prompt.Enabled = true
								end
							end
						end

					end
				end
			elseif not char:FindFirstChild("Handcuffs") then
				for _, player in pairs(players:GetPlayers()) do
					if player ~= plr then
						if player.Character then
							local character = player.Character
							for _, prompt in pairs(character:GetDescendants()) do
								if prompt:IsA("ProximityPrompt") and prompt.Name == "Arrest" then
									prompt.Enabled = false
								end
							end
						end
					end
				end
			end
		end
	end
end)()

You may need to increase the wait.task() time as running a loop through all players every 0.5 seconds might be too frequent.

1 Like

can you not change the variable names?

I did it to make it easier to understand when I was going through it, you’re welcome to change them back.

Because of this, the script does not work and I cannot figure out what names you chenged.

this is not a complete part of the script. where are more lines

That might be where the issue occurs then.

no errors, but the script stopped working completely

Move it to StarterCharacterScripts.

it was already there. before that, the script stopped working after the first arrest (all promps disappears), and now they don’t even appear

Try StarterPlayerScripts instead. Are you receiving any errors in console?