Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 1 year ago

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)
0
Why are you setting the humanoid health to 0? Kingu_Criminal 205 — 1y

1 answer

Log in to vote
0
Answered by
boredlake 256 Moderation Voter
1 year ago

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.

0
All humanoids have HumanoidRootPart wdym? T3_MasterGamer 2189 — 1y
0
Except for NPCs built by noobs. T3_MasterGamer 2189 — 1y
0
(no offense) T3_MasterGamer 2189 — 1y
0
Well why else would there be a problem boredlake 256 — 1y
Ad

Answer this question