How to do I fix this bug in my code of "ServerScriptService.Script:2: attempt to index nil with 'GetMouse'" in Line 2?
local t = 1;
local mouse = game.Players.LocalPlayer:GetMouse();
local hrp = game.Players.LocalPlayer.CharacterAdded:Wait():WaitForChild("HumanoidRootPart");
local bball = game.ServerStorage.PracticeBall
local rs = game:GetService("RunService").RenderStepped;
mouse.Button1Down:Connect(function()
local g = Vector3.new(0, -game.Workspace.Gravity, 0);
local x0 = hrp.CFrame * Vector3.new(0, 2, -2)
-- calculate the v0 needed to reach mouse.Hit.p
local v0 = (mouse.Hit.p - x0 - 0.5*g*t*t)/t;
local c = bball:Clone();
c.CanCollide = true;
c.Anchored = true;
c.Parent = game.Workspace;
-- have the ball travel that path
local nt = 0;
while (nt < t*2) do
c.CFrame = CFrame.new(0.5*g*nt*nt + v0*nt + x0);
nt = nt + rs:Wait();
end
end)

2 comments
Is this a server script? It's the only case I can think of where LocalPlayer is nil.
It is.