Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Attempt to index with nil 'CFrame'. How do i fix it?

Attempt to index with nil 'CFrame'. I have this error in kill script. How can i fix it?

local Copy = script.Parent:Clone()
local NPC = script.Parent
local Humanoid
for i,v in pairs(NPC:GetChildren()) do 
	if v:IsA('bot') then 
		Humanoid = v 
	end 
end

script.Parent.Touched:connect(function(hit)
	if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid.Health = 0
		local character = hit.Parent
		local KnockBack = Instance.new("BodyVelocity")
		KnockBack.P = math.huge
		KnockBack.Parent = character:FindFirstChild("HumanoidRootPart")
		KnockBack.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		KnockBack.Velocity = character:FindFirstChild("HumanoidRootPart").CFrame.lookVector * -132
		game.Debris:AddItem(KnockBack, 0.5)
	else
		if hit.Name == "Detector" then
			Copy.Parent = NPC.Parent
			Copy:MakeJoints()
			NPC:Destroy()
		end
	end
end)

1 comment

0

Why are you setting the humanoid health to 0?

1 answer

From the sample of code you have provided, it seems that the variable character does not have a Child called HumanoidRootPart, so you should find what character does have and use that instead. For example, if your game is in R6 I believe it should be Torso instead.

4 comments

0

All humanoids have HumanoidRootPart wdym?

0

Except for NPCs built by noobs.

0

(no offense)

0

Well why else would there be a problem

This discussion is preserved as it was. New answers, comments, and votes are closed.