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

Attempt to index nil with CFrame?

Asked by
DemGame 271 Moderation Voter
4 years ago

I have a script that I want to make a projectile not move for 2 seconds and start moving again afterwards, but I get the "Attempt to index nil with CFrame" error. Here is my code:

local bullet = game.ReplicatedStorage["Cyborg Assets"].ball
local head = script.Parent.Parent:FindFirstChild("Head")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local event = Instance.new("RemoteEvent", ReplicatedStorage)
event.Name = "Cyborg SP3"
local debounce = false
--local sound = Instance.new("Sound")
--sound.Parent = head
--sound.SoundId = "rbxassetid://1382489817"
--sound.Volume = 2
--sound.Playing = false
--local sound2 = Instance.new("Sound")
--sound2.Parent = head
--sound2.SoundId = "rbxassetid://1382489817"
--sound2.Volume = 2
--sound2.Playing = false

local function Hurt(Part)
        if debounce == false then
            if Part.Parent:FindFirstChild("Humanoid") then
                Part.Parent.Humanoid.Health = Part.Parent.Humanoid.Health - 75
                Part.Parent.Humanoid.WalkSpeed = 8
                debounce = true
                wait(2)
                Part.Parent.Humanoid.WalkSpeed = 16
                debounce = false
            end
        end
end

local function shootbullet()
    local debounce = false
    local Fireball = bullet:Clone()
    print("remoteEvent recieved")
    --sound.Playing = true
    Fireball.BrickColor = BrickColor.new("Institutional white")
    Fireball.Transparency = 0
    Fireball.TopSurface = 0
    Fireball.BottomSurface = 0
    Fireball.CanCollide = false
    Fireball.CFrame = head.CFrame * CFrame.new(0,0,-15)
    Fireball.Parent = game.Workspace
    wait(2)
    Fireball.CFrame = head.CFrame * CFrame.new(0,0,-15)
    --sound2.Playing = true
    local BodyVelocity = Instance.new("BodyVelocity")
    BodyVelocity.Parent = Fireball
    BodyVelocity.maxForce = Vector3.new(math.huge, math.huge, math.huge)
    BodyVelocity.velocity = head.CFrame.lookVector*75
    Fireball.Touched:connect(Hurt)
    wait(10)
    Fireball:Destroy()
end
event.OnServerEvent:connect(shootbullet)
0
which line is erroring? maybe you need to change line 1 to :WaitForChild(“ball”) Spiritlotus 151 — 4y
0
Line 41 is erroring. DemGame 271 — 4y
0
check if the head variable is nil, also where is the script located? royee354 129 — 4y
0
the script is located in StarterCharacterScripts. DemGame 271 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

when your changing a cframe you must add CFrame.New try doing this in line 41

Fireball.CFrame = CFrame.New(head.CFrame * CFrame.new(0,0,-15))

if that doesnt work then

Fireball.CFrame = CFrame.New(head.CFrame * Vector3.new(0,0,-15))
Ad

Answer this question