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)

4 comments
which line is erroring? maybe you need to change line 1 to :WaitForChild(“ball”)
Line 41 is erroring.
check if the head variable is nil, also where is the script located?
the script is located in StarterCharacterScripts.