Mouse.Hit not working?

So I tried to make a fly script for my admin commands system and I got this error


Heres my code:

elseif args[1] == "fly" then
		if Players:FindFirstChild(args[2]) then
			local Player = Players:FindFirstChild(args[2])
			local Mouse = Player:GetMouse()
			local Character = Player.Character
			local Head = Character:WaitForChild("Head")
			local BodyVel = Instance.new("BodyVelocity",Head)
			BodyVel.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			BodyVel.Velocity = Mouse.Hit.lookVector * 100
		end
	else
		commandFailed(player)
	end
end

You can only call Player:GetMouse() from within a local script, and I would guess that’s probably the reason it results in nil.

You’ll have to use the same loop in a LocalScript and then return the Mouse object to the regular server Script using a RemoteEvent.

I can elaborate further if you’d like, but that should fix the issue.

1 Like