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

ServerScriptService.Script:62: attempt to index nil with 'lookVector'?

Im having a problem with mouse.lookvector

The Client Script

local UserInputService = game:GetService("UserInputService")

local player = game.Players.LocalPlayer

local Mouse = player:GetMouse()

local character = player.Character or player.CharacterAdded:Wait()

local PlayerFolder = character:WaitForChild("PlayerFolder")


local PlayerWelds = character:WaitForChild("PlayerWelds")

local Key = script.Keybind.Value



local active = false
local debounce = false
local cooldown = 2


UserInputService.InputBegan:Connect(function(Input ,IsTyping)
	if IsTyping then return end
	if (Input.KeyCode == Enum.KeyCode[Key]) then
		if debounce == false and active == false then
			debounce = true
			game.ReplicatedStorage.FireBallEvent:FireServer(active,PlayerFolder,PlayerWelds)
		end
	end
end)


UserInputService.InputEnded:Connect(function(Input)
	if (Input.KeyCode == Enum.KeyCode[Key]) then
		if debounce == true and active == false then
			active = true
			game.ReplicatedStorage.FireBallEvent:FireServer(active, PlayerFolder, Mouse.Hit)
		end
	end
end)


game.ReplicatedStorage.FireBallEvent.OnClientEvent:Connect(function()
	wait(cooldown)
	debounce = false
	active = false
end)

The Server Script

local RepStorage = game:GetService("ReplicatedStorage")
local Projectiles = RepStorage.Projectiles
local RightHand = nil
local holdanimTrack = nil
local holdAnim = nil
local InnerFireBall = nil
local mainWeld = nil

game.ReplicatedStorage.FireBallEvent.OnServerEvent:Connect(function(Player, active, PlayerFolder, PlayerWelds, PlayerBodyMovers)
	if active == false then
	local char = Player.Character
	local dmg = char:FindFirstChild("dmgValue")
	local Humanoid = char:FindFirstChild("Humanoid")
	
	RightHand = char:FindFirstChild("RightHand")
	
	holdAnim = Instance.new("Animation",PlayerFolder)
	holdAnim.AnimationId = "rbxassetid://4885604627"
	holdAnim.Parent = PlayerFolder
	
	holdanimTrack = Humanoid:LoadAnimation(holdAnim)
	holdanimTrack:Play()
	
	InnerFireBall  = Projectiles:WaitForChild("Inner"):Clone()
	InnerFireBall.Size = Vector3.new(0.1,0.1,0.1)
	InnerFireBall.Parent = PlayerFolder
	
	InnerFireBall.CFrame = RightHand.CFrame * CFrame.new(0,-0.5,0)
	mainWeld = Instance.new("Weld")
	mainWeld.Part0 = RightHand
	mainWeld.Part1 = InnerFireBall
	mainWeld.C0 =  RightHand.CFrame:Inverse()
	mainWeld.C1 = InnerFireBall.CFrame:Inverse()
	mainWeld.Name = "InnerFireBallWeld"
	mainWeld.Parent = PlayerWelds
		
	for fireballsizecount = 1,60,1 do
		InnerFireBall.Size = InnerFireBall.Size + Vector3.new(0.03,0.03,0.03)
		wait(0.1)
		end
	end
end)

game.ReplicatedStorage.FireBallEvent.OnServerEvent:Connect(function(Player, active, PlayerFolder, PlayerWelds, PlayerBodyMovers, Mouse)
	if active == true then
	local char = Player.Character
	local Humanoid = char:WaitForChild("Humanoid")
	
	holdanimTrack:Stop()
	holdAnim:Destroy()
	
	local releaseAnim = Instance.new("Animation",PlayerFolder)
	releaseAnim.AnimationId = "rbxassetid://4890399550"
	
	local releaseAnimTrack = Humanoid:LoadAnimation(releaseAnim)
	releaseAnimTrack:Play()
	
	mainWeld:Destroy()
	
	local BodyVelocity = Instance.new("BodyVelocity")
	BodyVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	BodyVelocity.Velocity = Mouse.lookVector*30
	BodyVelocity.Parent = InnerFireBall
	
	game.ReplicatedStorage.FireBallEvent:FireClient(Player)	
	end
end)


1 comment

0

LookVector is a property of CFrame that represents the direction of the lookvector.

1 answer

✓ Accepted answer

LookVector is a property of CFrame that represents the direction that the object is facing.

It's not a property of mouse. You can use mouse.UnitRay if you want to get the line that the mouse creates to the world space through current camera.

CFrame Wiki

Mouse Wiki

Example

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