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

Attempt to index nil with lookVector?

Asked by 4 years ago
Edited 4 years ago

I am making an RPG. I have scripted a working magic system and it works very well on PC. I wanted to add mobile support, which would fire this script when the button is pressed. However, I get the error in the title. Please help.

--// Services \\--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Debris = game:GetService('Debris')

--// Variables \\--
local Remote = ReplicatedStorage.FireBallEvent
local FireBall = ReplicatedStorage.FireBall
local player = game.Workspace:FindFirstChild(game.Workspace.PlayerName.Value)

--// Settings \\--
local Damage = 20

local ServerDebounces = {}

Remote.OnServerEvent:Connect(function(plr, Mouse)
 if not ServerDebounces[plr] then
  ServerDebounces[plr] = true

  local Char = plr.Character or plr.CharacterAdded:Wait()

  local FireBallClone = FireBall:Clone()
  FireBallClone.CFrame = Char.HumanoidRootPart.CFrame * CFrame.new(0,0,-3)
  FireBallClone.Parent = workspace

  local BodyVelocity = Instance.new("BodyVelocity")
  BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  BodyVelocity.Velocity = Mouse.lookVector ----- This is the problem line
  BodyVelocity.Parent = FireBallClone

  spawn(function()
   for i = 0, 1000 do
    wait()
    FireBallClone.Size = FireBallClone.Size + Vector3.new(0.07,0.07,0.07)
    BodyVelocity.Velocity = Mouse.lookVector*i
   end
  end)
  ServerDebounces[plr] = false
  Debris:AddItem(FireBallClone, 10)

  local Debounce = true
  FireBallClone.Touched:Connect(function(h)
   if h.Parent:FindFirstChild('Humanoid') and h.Parent.Name ~= plr.Name and Debounce then   
    Debounce = false   
    local Enemy = h.Parent.Humanoid
    Enemy:TakeDamage(Damage)
    FireBallClone.Transparency = 1
    BodyVelocity:Destroy()
    wait(1)
    FireBallClone:Destroy()
    wait(3)
    Debounce = true
   end
  end)
 end
end)

The local script in StarterGui will fire the event when the button is pressed:

local contextActionService = game:GetService("ContextActionService")
local Mouse = game.Players.LocalPlayer:GetMouse()

function onButtonPress()
game.ReplicatedStorage.FireBallEvent:FireServer(Mouse)
end

local mobilebutton = contextActionService:BindAction("ActivateSpellButton", onButtonPress, true, "Q")
contextActionService:SetPosition("ActivateSpellButton", UDim2.new(0.72,-25,0.20,-25))
contextActionService:SetImage("ActivateSpellButton", "http://www.roblox.com/asset/?id=247421777")
0
Could you send the client script so I can see what Mouse is orcazate 170 — 4y
0
Ok iiPizzaCraver 71 — 4y
0
I've updated the post iiPizzaCraver 71 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Not entirely sure, but I think it's LookVector (with a capital l), not lookVector.

0
I've checked the wiki, its not a capital l. Please can u comment that instead of putting it as an answer please iiPizzaCraver 71 — 4y
Ad

Answer this question