Hi. Currently, I am working on a rocket launcher for my game, but wen I go to shoot, the function to set the rockets CFrame is saying the first argument is either missing or nil. Here is the script:
Tool.Activated:Connect(function()
if Tool.Enabled == true then
Tool.Enabled = false
local SpawnPosition = (Tool.Handle.CFrame * CFrame.new(5, 0, 0)).p
print(SpawnPosition)
local RocketCFrame = CFrame.lookAt(SpawnPosition, GetMouse:InvokeClient())
local FiredRocket = Rocket:Clone() --Setup rocket
FiredRocket.CFrame = RocketCFrame
FiredRocket.Position = SpawnPosition
FiredRocket.Velocity = RocketCFrame.LookVector * 60
FiredRocket.Parent = game.Workspace
end
end
local RocketCFrame = CFrame.lookAt(SpawnPosition, GetMouse:InvokeClient())
This line is most likely the problem, I’d imagine the getmouse invoke is returning nil be sure to print the results of it; Also what did the print(SpawnPosition) output?
local RocketCFrame = CFrame.lookAt(SpawnPosition, GetMouse:InvokeClient())
After this assignment expression, the variable “RocketCFrame” is still a reference to a nil value, so when you index the “CFrame” property of the fired rocket and assign it this nil value an error is thrown/raised as the “CFrame” property can only be assigned a “CFrame” value of the “CFrame” class.